Thursday, March 22, 2012

Why the source database not updated?

Hi there:
Following is the code, after change the Dataset, accepte the change made to the dataset and excute the update of Adapter, nothing happened to the database source database, what's wrong?
Thanks!
CM

---------------
Private Sub UpdateApartment()
Dim i As Integer
Dim myDataAdapter As OleDbDataAdapter
Dim myDataset As DataSet
Dim MyConnection As OleDbConnection

i = Session("intIndex")
myDataset = Session("tableApt")
myDataAdapter = Session("myAdapter")
MyConnection = Session("ADMConn")
With myDataset.Tables("Apt")
.Rows(i)("Company") = txtCompanyName.Text
.Rows(i)("BuildingName") = txtBuildingName.Text
End With

myDataset.AcceptChanges()
MyConnection.Open()
myDataAdapter.Update(myDataset)
MyConnection.Close()

End SubSorry, the above code result this error:

System.InvalidOperationException: Update unable to find TableMapping['Table'] or DataTable 'Table'.

I changed the update code to:
myDataAdapter.Update(myDataset, "Apt")

The error is gone, but the source database still not updated.

CM

"CM" <cm111@.hotmail.com> wrote in message news:eCApYAn0DHA.4032@.tk2msftngp13.phx.gbl...
Hi there:
Following is the code, after change the Dataset, accepte the change made to the dataset and excute the update of Adapter, nothing happened to the database source database, what's wrong?
Thanks!
CM

---------------
Private Sub UpdateApartment()
Dim i As Integer
Dim myDataAdapter As OleDbDataAdapter
Dim myDataset As DataSet
Dim MyConnection As OleDbConnection

i = Session("intIndex")
myDataset = Session("tableApt")
myDataAdapter = Session("myAdapter")
MyConnection = Session("ADMConn")
With myDataset.Tables("Apt")
.Rows(i)("Company") = txtCompanyName.Text
.Rows(i)("BuildingName") = txtBuildingName.Text
End With

myDataset.AcceptChanges()
MyConnection.Open()
myDataAdapter.Update(myDataset)
MyConnection.Close()

End Sub

0 comments:

Post a Comment