Hi guys
I have a problem in my project.Below I mention the coding I wrote it for testing purpose.
In below coding the second while loop never run,only
SqlDataReader reader = DbCon.Get_Invoices();
int x = 0;
while (reader.Read())
{
x++; 1
}
MessageBox.Show(x.ToString());
chart2.DataBindCrossTable(reader, "ExecutiveCode", "Date1", "Total", "");
foreach (Series series in chart2.Series)
{
series.ChartType = SeriesChartType.Line;
}
chart2.ResetAutoValues();
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("tbldata");
int intIdx = 0;
for (int i = 0; i < reader.FieldCount; i++)
{
dt.Columns.Add(reader.GetName(i), reader.GetFieldTypei));
}
while (reader.Read())
{ 2
x++; }
MessageBox.Show(x.ToString());
while (reader.Read())
{ 3
MessageBox.Show("test");
DataRow r = dt.NewRow();
if (intIdx >= intSkip)
{
for (int i = 0; i < reader.FieldCount; i++)
{
r[i] = reader[i];
}
dt.Rows.Add(r);
}
In above coding 3rd while loop never runs and it never give me Meassage I expected.1 and 2 while loop work and I generate the x value also.Please tell me y that 3rd loop never work
Thanks
Tank50
Reader has reached the end after the first while loop, and the "context" of it is basically EOF. Neither your second or third loop run. The only reason you think your second loop runs is because it is printing the correct value for x outside of the loop, which was calculated in the first loop. Try resetting reader before each loop.
Reputation Points: 25
Solved Threads: 3
Junior Poster in Training
Offline 89 posts
since Oct 2006