The DataReader and integers

T

Tarun Mistry

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
 
A

A.Kahtava

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

A.Kahtava

The DataReader has many get methods..

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top