int a ;
SqlCommand cmd = new SqlCommand (" Select * From items order by ItemID ", conn );
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
a = reader.GetInt32(0);
if (reader.HasRows == false)
{
dataGridView1.Visible = false;
}
else
{
dataGridView1.Visible = true;
DataTable dt = null;
dt = new DataTable();
dt.Load(reader);
dataGridView1.DataSource = dt;
if (reader.IsClosed == true)
{
break;
}
}
I want to ask that is the reader closed automatically, because here am not using reader.Close() and still it is closed? also , in my items table i have the first record as
ItemId | ItemName
1 Bag
2 Laptop
8 Weighing Machine
But, when this data is displayed in the datagridview then the row 1 , that is, the itemname "BAG" is not displayed. why so?