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++;                                                 [B] 1[/B]
             }
           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())
           {                                                      [B]2[/B]
               x++;     }                                   
           MessageBox.Show(x.ToString());

         while (reader.Read())
          {                                                    [B]3[/B]
          
          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

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++;                                                 [B] 1[/B]
             }
           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())
           {                                                      [B]2[/B]
               x++;     }                                   
           MessageBox.Show(x.ToString());

         while (reader.Read())
          {                                                    [B]3[/B]
          
          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.

Hi

Yes your right,so how I reset sqldatareader?

Thanks
Tank50

This article has been dead for over six months. Start a new discussion instead.