Query regarding DataReader

  • Thread starter Thread starter santiago
  • Start date Start date
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?
 
santiago,

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

Kerry Moorman
 
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

Back
Top