Determine number of columns in oledbdatareader...

lidds

Well-known member
Joined
Nov 9, 2004
Messages
210
Determine number of rows in oledbdatareader...

I need to find out how many rows are in my datareader.

The code is as follows:

Code:
                Dim myReader As OleDb.OleDbDataReader = Nothing
                Dim myCmd As New OleDb.OleDbCommand("spQryIssue")
                myCmd.CommandType = CommandType.StoredProcedure
                myReader = myDB.RunMyDataQuery(myCmd)

Is there something like
Code:
myReader.rows.count()
I know you can do
Code:
Do While myReader.Read
but I physically need the number

Thanks

Simon
 
Last edited by a moderator:
I have not tried this, so you will have to give it a shot:
Code:
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "spQryIssue";
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Connection = // some OleDbConnection

OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;

DataSet ds = new DataSet();
da.Fill(ds);

foreach (DataTable dt in ds.Tables)
{
    Console.Write("ROW COUNT: " + dt.Rows.Count);
}
Basically you want to use a OleDbDataAdapter to fill a DataSet. Then access the individual DataTable objects in the DataSet.
 
Thanks, did not expect it to be that much hassle :)

Just out of interest there is probably only going to be no more than 10 rows in the dataReader, would it be quicker to loop through and count them rather than to do the DataSet route????

Thanks for your help

Simon
 
Well, coding that is going to probably be a bigger hassle than what I posted. Plus, getting your results into a DataSet is a lot more useful throughout .NET.
 
The only problem with using datareaders is, I believe the values of the parameters arent set until the datareader is closed.
 
my sql is now

SELECT * FROM myTable
SELECT @@ROWCOUNT AS rowNum

But how do I get the rowcount value?? I have tried the following but does not seem to work.

Code:
MsgBox(myReader.Item("rowNum").ToString())

Thanks for all your help guys

Simon
 
Last edited by a moderator:
Back
Top