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.
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"
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...
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!
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.
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);
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.