0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by hitro456
0

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.

0

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...........

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.