VB2010 1 つの DataSet があり、複数のテーブルを追加し、これらのテーブルに入力してから、それらのレコードを Access データベースに挿入します。
'create a new DataSet
Dim dsNav As New DataSet
'first table
Dim daTrips As New OleDb.OleDbDataAdapter("SELECT * FROM Trips", connNav)
daTrips.Fill(dsNav, "Trips")
Dim cbTrips As New OleDb.OleDbCommandBuilder(daTrips)
'second table
Dim daCars = New OleDb.OleDbDataAdapter("SELECT * FROM Cars", connNavDb)
daCars.Fill(dsNav, "Cars")
Dim cbCars As New OleDb.OleDbCommandBuilder(daCars)
'here i open a huge text file and depending on the data i encounter, I create
'a new DataRow and add it to the appropriate table. i add many new rows to each
'table. for example
Dim dsNewRow As DataRow = {tblCars}.NewRow()
dsNewRow.Item("CarId") = textline.Substring(0, 10)
dsNewRow.Item("CarMake") = textline.Substring(11, 15)
tblCars.Rows.Add(dsNewRow)
'i finish reading the text file and filling up the tables in the one DataSet
'now i want to insert those records into the Access db
Dim rowCnt1 As Integer = daTrips.Update(dsNav, "Trips")
Dim rowCnt2 As Integer = daCars.Update(dsNav, "Cars")
最初の更新は機能しますが、2 回目の更新で例外が発生します。
System.Data.dll System.Data.OleDb.OleDbException (0x80040E14): INSERT INTO ステートメントで構文エラーが発生しました。System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors (RowUpdatedEventArgs rowUpdatedEvent、BatchCommandInfo[] batchCommands、Int32 commandCount) で System.Data.Common.DbDataAdapter.UpdatedRowStatus (RowUpdatedEventArgs rowUpdatedEvent、BatchCommandInfo[] batchCommands、Int32 commandCount) で System.Data.Common .DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) で System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) で System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
私はさまざまな記事を見てきましたが、それらはすべて、複数の DataTables を含む 1 つの DataSet でデータベースを更新することを提案していますが、なぜこれが爆撃なのか理解できません。