I have a problem when storing data into a SqlDataReader. When i assing the sdr variable, at the point where connection.close(), the sdr variable becomes empty. Why?
string strConnection = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
SqlDataReader sdr = null;
using (SqlConnection connection = new SqlConnection(strConnection))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand("GetProducts", connection))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
sdr = cmd.ExecuteReader();
}
connection.Close();
}
return (sdr);