|
-
October 29th, 2002, 09:54 AM
#1
Recordcount DataSet???
Im new to trying to use ADO.NET but have had alot of previous experience with standard ADO.
How do you get a recordcount for a dataset?
This is what i am doing now.. but I know there has to be a better way.
Code:
Private Function MaxRecords() As Integer
Dim sqlSelect As String
sqlSelect = "Select [Question] From [tblQuestions]"
Dim con As New OleDbConnection(ConnectionString)
Dim cmd As New OleDbCommand(sqlSelect, con)
Dim reader As OleDbDataReader
Try
con.Open()
reader = cmd.ExecuteReader()
MaxRecords = 0
Do While reader.Read()
MaxRecords = MaxRecords + 1
Loop
reader.Close()
Catch err As Exception
lblQuestion.Text = "Error reading survey data. "
lblQuestion.Text &= err.Message & " "
Finally
If (Not con Is Nothing) Then
con.Close()
End If
End Try
End Function
-
October 31st, 2002, 10:52 PM
#2
Your not using a DataSet in this example. You cannot get a RecordCount from a DataReader. The DataReader is a connected Forward Only object. You can iterate through all of the records and have a counter variable to maintain the count.
You can get the count from a table in a DataSet. Remember a DataSet is a container of Tables which are containers of Rows.
MyRecCount = MyDataSet.Tables(0).Rows.Count
Mike Huguet
Senior Consultant
Software Architects, Inc.
MCSD, MCDBA, MCSA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|