lault
Sep 20th, 2002, 10:45 AM
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.
'' 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
'' 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