Groups | Blog | Home
all groups > c# > february 2006 >

c# : The DataReader and integers


A.Kahtava
2/16/2006 3:12:27 PM
The DataReader has many get methods..

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

DataReader Get method:
int integerColumnValue = r.GetInt(i);
A.Kahtava
2/16/2006 3:12:45 PM
The DataReader has many get methods..

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

DataReader Get method:
int integerColumnValue = dataReader.GetInt(i);
Tarun Mistry
2/16/2006 10:35:59 PM
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

AddThis Social Bookmark Button