Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.NET equivalent of recordcount??? 1

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
All,

Does ADO.NET have an equivalent to ADO's .RecordCount?

I am returning records in to a SqlDataReader and want to know how many records are coming back. I do not want to hit the database seperately to determine the recordcount.

Thanks,
Mark
 
Dim SqlAdapter As SqlDataAdapter
Dim DS As DataSet = New DataSet
sqlstmt = "select * from temp"
cnn ' is the connection
SqlAdapter = New SqlDataAdapter(sqlstmt, cnn)
SqlAdapter.Fill(DS, "dsname")



RowCnt = DS.Tables("dsname").Rows.Count
 
This brings up another question I've been wondering about. Now that you've got the example up here... what is the "dsname" you reference in the last line in your code? temp is the name of the table, cnn is the connection object, DS is the DataSet object name...

What is the "dsname"?

dpdoug
 
DS is the dataset object, but dsname is the name given to the dataset.

Its the same with datatables, you can have a DT datatable object, but you can actually specify a name for it, like "customers" or whatever.

:)

hth

D'Arcy
 
Also the same DataSet can hold many DataTables. The Fill method used by the DataAdapter object fills one of the DataTables, that for better usage you can name "whatever"

so that later you can use your DataSet Object with many DataTables:

in c#
int iTable1Rows = ds.Tables["FirstTable"].Rows.Count
int iTable2Rows = ds.Tables["SecondTable"].Rows.Count

hth

Daren J. Lahey
Just another computer guy...
FAQ183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
Support your forums TODAY!
 
Hi,

I would like to repeat the question. The initial question was for datareader and not dataset. Is it possible to get the recordcount in case of datareader, as i dont like to use dataset in all the cases. If no then can there be any work around.

Thanks
Ronak
 
according to ms there's no sollution:
the only way is to create a datatable and use the count property of the rows collection.
Or you could use a select count(x)...

But why do you want a recordcount? Just for info or to do other things with it?

At this moment i use a variable during the "while read()" statement

while (myRdr.Read()){
i++;
myArrayList.Add(new MyObject myRdr.GetString(0),myRdr.GetString(1)));
}
myRdr.Close();
myObject = new MyObject; // it should say MyObject[myRdr.Recordcount]
myArrayList.CopyTo(myObject);
myComboBox.Items.AddRange(myObject);
 
sorry forgot something i see
>> myOjbect = new MyObject // it should say MyObject[myRdr.Recordcount]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top