Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Counting Records added and modified in a DataSet

Counting Records added and modified in a DataSet

Scheduled Pinned Locked Moved Visual Basic
databasetutorialquestionannouncement
4 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Quecumber256
    wrote on last edited by
    #1

    Hi Everyone: Cleako showed me a link where I can return records that were either added to or modified in a DataSet. What I would like to do is show the user a message giving them the number of records that where added to the dataset and a number of existing records that where modified before they commit update to the database. I didn't see anything like - MyDataSet.GetChanges(DataRowState.Modified.Count) or MyDataSet.GetChanges(DataRowState.Added.Count) which would make sense but isn't in the DataRowState class. Anyone have an idea on how to accomplish this? Thanks, Quecumber256

    D 1 Reply Last reply
    0
    • Q Quecumber256

      Hi Everyone: Cleako showed me a link where I can return records that were either added to or modified in a DataSet. What I would like to do is show the user a message giving them the number of records that where added to the dataset and a number of existing records that where modified before they commit update to the database. I didn't see anything like - MyDataSet.GetChanges(DataRowState.Modified.Count) or MyDataSet.GetChanges(DataRowState.Added.Count) which would make sense but isn't in the DataRowState class. Anyone have an idea on how to accomplish this? Thanks, Quecumber256

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The answer is staring you in the face. What does DataSet.GetChanges() return?? Another DataSet object! A DataSet is a collection of DataTables, which is a collection of DataRow objects. You can get the number of tables in this new DataSet quite easily:

      Dim changes As DataSet = MyDataSet.GetChanges(DataRowState.Modified)
      If changes IsNot Nothing AndAlso Not changes.HasErrors Then
          ' Get the number of tables in this changed dataset.
          Dim numTablesChanged As Integer = changes.Tables.Count
      
          ' Enumerate through these tables and add up the number of rows in each.
          Dim numTotalRecordChanges As Integer
          For Each t As DataTable In changes.Tables
              numTotalRecordChanges += t.Rows.Count
          Next
      End If
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      Q 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The answer is staring you in the face. What does DataSet.GetChanges() return?? Another DataSet object! A DataSet is a collection of DataTables, which is a collection of DataRow objects. You can get the number of tables in this new DataSet quite easily:

        Dim changes As DataSet = MyDataSet.GetChanges(DataRowState.Modified)
        If changes IsNot Nothing AndAlso Not changes.HasErrors Then
            ' Get the number of tables in this changed dataset.
            Dim numTablesChanged As Integer = changes.Tables.Count
        
            ' Enumerate through these tables and add up the number of rows in each.
            Dim numTotalRecordChanges As Integer
            For Each t As DataTable In changes.Tables
                numTotalRecordChanges += t.Rows.Count
            Next
        End If
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        Q Offline
        Q Offline
        Quecumber256
        wrote on last edited by
        #3

        Dave: If I read your example right you are sending the DataSet of only those records that where modified? So your example will show the total number of records in the dataset that where modified(changed)? FYI - I'm so wet behind the ears in Visual Studio .NET there is a good chance I will drown :-). Thank you, Quecumber256

        D 1 Reply Last reply
        0
        • Q Quecumber256

          Dave: If I read your example right you are sending the DataSet of only those records that where modified? So your example will show the total number of records in the dataset that where modified(changed)? FYI - I'm so wet behind the ears in Visual Studio .NET there is a good chance I will drown :-). Thank you, Quecumber256

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          All you have to do is read the documentation on DataSet.GetChanges()[^].

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups