Hi everyone

I am executing a query on sqlreader object i.e.

rdr = cmd.executereader();

now I get a value rdr[0] = 100; but this value is in reader object.

I want to transfer that value rdr[0] to integer variable how can I do that?

I tried int.parse, int.tryparse, convert.int32..etc
it says string not in correct format.
please reply asap

Recommended Answers

All 2 Replies

try this

int returnVal = 0;
 if (rdr[0] != DBNull.Value) {
   returnVal = Convert.ToInt32(rdr[0]);
}

I wonder how VS did not give you auto suggestion for this.

try this

int returnVal = 0;
 if (rdr[0] != DBNull.Value) {
   returnVal = Convert.ToInt32(rdr[0]);
}

I wonder how VS did not give you auto suggestion for this.

Oh man its working miraculously
when i tried the same thing (convert.toint32() ) it didnt work.
Thanks a lot...........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.