In my page mysqlDataReader returns 4 records.Whenever I load this mysqlDataReader to DataTable using
DataTable dt = new DataTable();
dt.Clear();
dt.Load(dr);
DataTable shows only last record.
my Code is:
DataTable dt = new DataTable();
for (int i = 0; i < gvDemoBatches.Rows.Count; i++)
{
CheckBox cb = (CheckBox)gvDemoBatches.Rows[i].FindControl("checkSelect");
if (cb.Checked == true)
{
Panel2.Visible = true;
objBEBatch.BatchID = Convert.ToInt32(((Label)gvDemoBatches.Rows[i].Cells[0].FindControl("lblBatchId")).Text);
MySqlDataReader dr = objBLAddNewDemo.GetParticularDemoData(objBEBatch);
dt.Clear();
dt.Load(dr);
}
}
"GetParticularDemoData" stored Procedure Returns 7 rows.but datatable shows only last record.
Sumit Kesarwani
01-Sep-2014your are adding rows to datatable inside loop. So the last loop record will be saved in the datatable
for (int i = 0; i < gvDemoBatches.Rows.Count; i++)
{
will execute multiple times and inside this you have
MySqlDataReader dr = objBLAddNewDemo.GetParticularDemoData(objBEBatch);
dt.Clear();
dt.Load(dr);
So the data table will contain the data only for the last row of the gridview where cb.Checked == true)