Best practice to query data from MS SQL Server in C Sharp?
Posted
by
Bruno
on Programmers
See other posts from Programmers
or by Bruno
Published on 2012-01-21T00:35:26Z
Indexed on
2012/10/10
9:52 UTC
Read the original article
Hit count: 445
What is the best way to query data from a MS SQL Server in C Sharp?
I know that it is not good practice to have an SQL query in the code.
Is the best way to create a stored procedure and call it from C Sharp with parameters?
using (var conn = new SqlConnection(connStr))
using (var command = new SqlCommand("StoredProc", conn) {
CommandType = CommandType.StoredProcedure }) {
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
© Programmers or respective owner