Best practice to query data from MS SQL Server in C Sharp?
- by Bruno
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();
}