D
Dustin Wilson
I tried to write a record to an access database with the following code but
I get an error on the line:
da.Update(ds, "tblDrawingList")
The error text that comes up is as follows:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at DatabaseWriteTest.Form1.Button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\DWilson\My Documents\Visual Studio
Projects\DatabaseWriteTest\Form1.vb:line 120
Microsoft JET Database Engine
Does anyone know what I'm doing wrong here?
Thanks
Dustin
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conn As OleDbConnection
Dim da As OleDbDataAdapter
Dim cb As OleDbCommandBuilder
Dim ds As DataSet
Dim drNewRow As DataRow
Dim strConnection As String
Dim strSQL As String
Try
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & System.AppDomain.CurrentDomain.BaseDirectory() &
"CADTools.mdb"
strSQL = "SELECT * FROM tblDrawingList;"
conn = New OleDbConnection(strConnection)
da = New OleDbDataAdapter(strSQL, conn)
cb = New OleDbCommandBuilder(da)
ds = New DataSet
da.FillSchema(ds, SchemaType.Source, "tblDrawingList")
drNewRow = ds.Tables("tblDrawingList").NewRow()
drNewRow(0) = "8"
drNewRow(1) = "8"
drNewRow(2) = "0"
drNewRow(3) = "0"
ds.Tables("tblDrawingList").Rows.Add(drNewRow)
da.Update(ds, "tblDrawingList")
drNewRow = Nothing
ds.Dispose()
cb.Dispose()
da.Dispose()
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & vbCrLf & ex.Source)
End Try
End Sub
I get an error on the line:
da.Update(ds, "tblDrawingList")
The error text that comes up is as follows:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at DatabaseWriteTest.Form1.Button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\DWilson\My Documents\Visual Studio
Projects\DatabaseWriteTest\Form1.vb:line 120
Microsoft JET Database Engine
Does anyone know what I'm doing wrong here?
Thanks
Dustin
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conn As OleDbConnection
Dim da As OleDbDataAdapter
Dim cb As OleDbCommandBuilder
Dim ds As DataSet
Dim drNewRow As DataRow
Dim strConnection As String
Dim strSQL As String
Try
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & System.AppDomain.CurrentDomain.BaseDirectory() &
"CADTools.mdb"
strSQL = "SELECT * FROM tblDrawingList;"
conn = New OleDbConnection(strConnection)
da = New OleDbDataAdapter(strSQL, conn)
cb = New OleDbCommandBuilder(da)
ds = New DataSet
da.FillSchema(ds, SchemaType.Source, "tblDrawingList")
drNewRow = ds.Tables("tblDrawingList").NewRow()
drNewRow(0) = "8"
drNewRow(1) = "8"
drNewRow(2) = "0"
drNewRow(3) = "0"
ds.Tables("tblDrawingList").Rows.Add(drNewRow)
da.Update(ds, "tblDrawingList")
drNewRow = Nothing
ds.Dispose()
cb.Dispose()
da.Dispose()
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & vbCrLf & ex.Source)
End Try
End Sub