Where should i write database fetching line of codes ? directly writing in controller or by creating another data access layers ? //sample code
string cmdString = "select id from testdata where id=@val1 and name=@val2";
string connString = @"";
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@val1", c2.id);
comm.Parameters.AddWithValue("@val2",c2.name);
conn.Open();
}
}