Trouble getting row count from DataReader

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I am using the DataReader to populate an ASP table dynamically. I would
like to set the tables "visible" property based on the the data from my
query. For example, if I have at least one row of data, I will set visible
to true, otherwise, false.

How get I find out if I have at least one row of data? The code below is
from the CodeBehind of my asp form.

*****************************
OracleConnection conn = new OracleConnection(ConnectionString);
OracleCommand cmd = new OracleCommand("select * from customer where name =
'BOB', conn);
try
{
conn.Open();
IDataReader reader = cmd.ExecuteReader();
_grid.DataSource = reader;
_grid.DataBind();
}
finally
{
conn.Dispose();
}
*****************************

Thanks,
Kevin
 
I think your only option on a DataReader is to use the .Read property. It
returns false if it can't produce a record.

Otherwise, a dataset is necessary to get the actual record count.
 
Back
Top