Query regarding DataReader

S

santiago

I was trying to fill an object using DataReader. but the queries were
such that one query returned 14 columns and another returned 18
columns. i was trying to read data from reader in such a way that it
incorporated this in single method.

but the problem was that it was throwing an IndexOutOfRange exception

is there is way except for reading schema that i can fetch data only
if if exists?
 
K

Kerry Moorman

santiago,

The datareader's FieldCount property gives you the number of columns in the
current row.

Kerry Moorman
 
S

santiago

but isn't there some way like we do in asp.net

if(Session["UserID"]!=null)
{
int i = Convert.ToInt32(Session["UserID"]);
}

so can't we write like

if(reader["UserID"]!=null)
{
int i = Convert.ToInt32(reader["UserID"]);
}
 

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