Results 1 to 2 of 2

Thread: Updating Data Adapter

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    tennessee
    Posts
    7

    Question Updating Data Adapter

    My problem is in the following code. I get no errors or warnings, the project compiles, yet the database (*.mdb on local machine) is never updated. This code is executed when the user presses a "Save" button.

    Code:
          '' Setup SQL statement
            Dim sSQL As String
            sSQL = "Select * FROM custdata"
    
            '' Open database connection
            OpenDB()
    
            '' Setup data adapter and row number
            Dim rownum As Short
            Dim da As New OleDb.OleDbDataAdapter(sSQL, cn)
    
            '' Setup data set
            Dim ds As New DataSet()
    
            '' Setup Command Builder for updating dataset
            Dim comm As New OleDb.OleDbCommandBuilder(da)
            da.UpdateCommand = comm.GetUpdateCommand
    
            '' Fill data set 
            da.Fill(ds, "custdata")
    
            '' Add new row to data set
            ds.Tables("custdata").NewRow()
    
            '' Get number of rows
            rownum = ds.Tables("custdata").Rows.Count - 1
    
            '' Save customer data to dataset
            ds.Tables("custdata").Rows(rownum).Item("fname") = txtfname.Text
            ds.Tables("custdata").Rows(rownum).Item("middle") = txtmiddle.Text
            ds.Tables("custdata").Rows(rownum).Item("lname") = txtlname.Text
            ds.Tables("custdata").Rows(rownum).Item("street") = txtstreet.Text
            ds.Tables("custdata").Rows(rownum).Item("city") = txtcity.Text
            ds.Tables("custdata").Rows(rownum).Item("state") = txtstate.Text
            ds.Tables("custdata").Rows(rownum).Item("zip") = Int32.Parse(txtzip.Text)
    
            '' Update database
            ds.AcceptChanges()
            da.Update(ds, "custdata")
    
            '' Close database connection
            CloseDB()
    any help would be apreciated. Thanks

  2. #2
    Junior Member
    Join Date
    Oct 2002
    Posts
    31

    Talking

    get rid of the ds.AcceptChanges()
    that should fix the problem.

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