VB.NET DataSet Update Source Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have struggled with this all last week, I finally have my code running
without any error generations but zero records are being updated to a simple
Access file. The source table has no relationship and I include the primary
key in my SQL statement. There are no other users to conflict with, the
DataGrid is sucessfully populated with the Source Data. The load code is as
follows:

conn = New OleDbConnections(strPath)
da = New OleDbDataAdapter
da.SelectCommand = New OleDbCommand(strSQL, conn)
da.FillSchema(ds, SchemaType.Source, "SourceTable")
da.Fill(ds, "SourceTable")

ds.DataSetName = "ds_Table"
da.TableMappings.Add("SourceTable", "ds_Table")

cmdBuilder = New OleDbCommandBuilder(da)

With objDataGrid
.DataSource = ds.DefaultViewManager
.SetDataBinding(ds, "SourceTable")
End with

'Datagrid is updated and rows are deleted a Save function is triggered on
close
'by ds.HasChanges but no records are updated or deleted

lngUpdate = da.Update(ds, "SourceTable") 'Returns 0

Debug.WriteLine(cmdBuilder.GetInsertCommand.CommandText)
Debug.WriteLine(cmdBuilder.GetUpdateCommand.CommandText)
Debug.WriteLine(cmdBuilder.GetDeleteCommand.CommandText)

'No Error is generated

I am at a complete loss, I do not understand why the Source Table is not
updated?
Any help would be of great assistance.
 
Looks like you are mapping the SourceTable to the DataSet name.

From what I can tell from your example, the table in your source is called
SourceTable and the table you want created in the DataSet is called
SourceTable. Hence, it is unclear what you need the TableMapping.

Andrew Conrad
Microsoft Corp
 
Thats it! I removed the TableMappings function and now the data is saved. I
am still somewhat confused, just what is the TableMapping function used for?
The Access Table name is SourceTable which I named for testing purposes only.
The DataSet Name was "ds_Table", initially the reason why I used it was
because an earlier error was looking for it.
 
Back
Top