How to get datareader values into integer variable from database

Traitée How to get datareader values into integer variable from database

  • mercredi 15 août 2012 10:02
     
     
    Hi,
    i have the datareader values are dr= 10,30,0,12,0,42,... from database.
    i am not able to calculate the total count i.e the code as follows:

    <pre lang="cs">while (dr.Read())
                    {
                        int Count = 0;
                        Count = Count + int.Parse(dr[&quot;TotalCount&quot;].ToString());
                    }</pre>
     
    while executing this i am getting an error like:
    Index OutOfRange exception.

    please give me a valid solution.

    Thanks&Regards,
    Raghu.

Toutes les réponses

  • mercredi 15 août 2012 10:35
     
     Traitée
    i got the solution with some modification,that is as follows: int Count = 0; while (dr.Read()) { Count = Count + dr.GetInt32(1); } dayChart.Titles.Add("Shipped Orders Per Day " +Count); but i am not able to use dr object to next statement i.e the code as follows: int Count = 0; while (dr.Read()) { Count = Count + dr.GetInt32(1); } dayChart.Titles.Add("Shipped Orders Per Day " +Count); // here datareader vlues are not assigning why dr is gets closed? dayChart.Series["DaySeries"].Points.DataBind(dr, "Hour Of Day", "Total", "Tooltip=Hour Of Day, Label=Total");