hi mate, actually, I have started working with ado.net very recently and I’m not a much experienced programmer too. Thanks for telling me the way, it worked. The project I’m doing, I’ve got one more problem: I have to use Microsoft access as database for this project. Since I have been working with sql from whatever days I’ve learned ado.net, I have hardly used access before this project. Now when I’m trying to work with it, some of the things looking puzzling to me and I’m not able to figure out a way to resolve them. one recent is that I’m not able to store a double value which is not a currency. My user will be entering a value like 4.00 which I need to store in the database. I’m getting error while trying to store it with currency set as dataType. In access, I did not find a dataType that represents decimal/double number. Any idea how can I do it? I’m learning a lot from this new project, but still I’m stuck up in a lot of things before being able to complete the software that I am developing. Can you please help me doing this? Sameer. On 8/9/10, black ares <matematicianu2003@xxxxxxxxxxx> wrote: > Hello, you miss understood the use of the datareader. > The data reader is a class which help you to read results from a query row > by row. > So it is what we call connected way to use with databases. > After the line with executereader, > you must do > dr.read(); > then dr.get(x) or dr.get ("columnName"); > for your help, when you want to get only a number, > so when you know that the query you use will return only a value, so a table > formed from a row and a column, > you can use better executeScalar instead of others. > Execute scalar retyurns an object you can cast using regular casting > algoritm so you can do: > int val=(int)cmd.executescalar(...); > > ----- Original Message ----- > From: "sameer manohtra" <sameermanohtra@xxxxxxxxx> > To: "programmingblind" <programmingblind@xxxxxxxxxxxxx> > Sent: Monday, August 09, 2010 1:47 PM > Subject: help required in c# code > > > 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 > > __________ > View the list's information and change your settings at > //www.freelists.org/list/programmingblind > > __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind