help required in c# code

  • From: sameer manohtra <sameermanohtra@xxxxxxxxx>
  • To: programmingblind <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 9 Aug 2010 16:17:31 +0530

Hi mates,
I am doing a project in c# with ado.net and I got  stuck at a place.

At one place in the code, i’m reading a column of table of my database
and want to store it  in a local variable.

Basically, the table has a number, which I will use further for some
addition/subtraction operation.

The problem is, that I’m not able to convert the output of the
dataReader into integer.
It gives the following exception:

---
System.InvalidCastException was unhandled
  Message="Unable to cast object of type
'System.Data.OleDb.OleDbDataReader' to type 'System.IConvertible'."
---

my code is this:
---
con.Open();
                    OleDbCommand cmd = new OleDbCommand("select
lastBalance from Textile");
                    cmd.Connection = con;
                          OleDbDataReader dr= cmd.ExecuteReader();


                                                    dr.Close();
                                                    con.Close();

                                                     int balance =
Convert.ToInt32(dr);
   ---

I have tried all that I knew, but could not find  a solution.

Can you help?

Please, tell me how can I convert  the output of dataReader to an integer value.

The help will be appreciated.

sameer
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: