Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Determine number of rows in oledbdatareader...

 

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

 

The code is as follows:

 

               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

myReader.rows.count()

I know you can do

Do While myReader.Read

but I physically need the number

 

Thanks

 

Simon

Edited by lidds
Posted
I have not tried this, so you will have to give it a shot:
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.

Posted

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

Posted (edited)

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.

 

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

 

Thanks for all your help guys

 

Simon

Edited by lidds

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...