471,336 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

The DataReader and integers

Hello everyone, I am using the data reader to access the information within
a results set and then pass this information onto the constructor of my
classes.

Im using the following syntax to access the information:

dataReader["my_field"].ToString()

This is fine, however it simple will not play ball if i need the value in
integer format, I have to declare a string variable manually, cast the data
to string, then into an integer and then send this to my constructor.

Is there a quick and easy method to cast it into an integer within my
constructor call?

Many thanks,
Taz
Feb 16 '06 #1
2 5102
The DataReader has many get methods..

A couple options:
Casting:
int integerColumnValue = (int)dataReader["my_field"];

DataReader Get method:
int integerColumnValue = r.GetInt(i);

Feb 16 '06 #2
The DataReader has many get methods..

A couple options:
Casting:
int integerColumnValue = (int)dataReader["my_field"];

DataReader Get method:
int integerColumnValue = dataReader.GetInt(i);

Feb 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Yasutaka Ito | last post: by
6 posts views Thread by Ravi | last post: by
20 posts views Thread by Mark | last post: by
2 posts views Thread by Andrei Pociu | last post: by
1 post views Thread by Brent | last post: by
7 posts views Thread by Diffident | last post: by
3 posts views Thread by Johnny Jörgensen | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.