CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2000
    Location
    Ohio
    Posts
    238

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Houston
    Posts
    6
    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
  •  





Click Here to Expand Forum to Full Width

Featured