Just want to make sure this is the best way to call a connection, and grabbing data from a database, or should I some how call the datareader outside of the using statement? (in order to have the connection close quicker?) or is there anything you would personal change to this?
using (SqlConnection cn = new SqlConnection(connStr))
{
using (SqlCommand cm = new SqlCommand(connStr, cn))
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "GetExchRatesByDate";
cm.Parameters.Add("@Date", SqlDbType.VarChar).Value = txtStartDate.Text;
cn.Open();
SqlDataReader dr = cm.ExecuteReader();
while (dr.Read())
{
firstName = (string)dr["GivenName"];
lastName = (string)dr["sn"];;
}
dr.Close();
}
}