Topaz Filer - Email filing software
help! insert syntax error when using OleDbDataAdapter.Update
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

James (VIP)
Try the following code.

The datasouce is MS access file, and the table abc has only two columns:
1. ID (integer) key
2. section (integer) non-unique

And try the following code would cause an exception saying that "syntax
error in insert statement" during the myad.Update(mydtb) (I'm sure that it's
not the key problem, there's nothing at all in the table abc in the MDB file)

if i changed the column 2 name ("section“) to another one in the datasouce
(MDB file), let's say "num", the following code would work properly.

So I'm very confused!! Any help woul d be appreciated.

VB. NET code

Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\abc.mdb; Jet OLEDB:Database Password="

Private Sub initdb(ByRef conn As OleDbConnection)
conn = New OleDbConnection(connStr)
conn.Open()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conn As OleDbConnection
Dim mydtb As New DataTable
initdb(conn)
Dim mycommand As OleDbCommand = New OleDbCommand("select * from
abc", conn)

Dim myad As OleDbDataAdapter = New OleDbDataAdapter(mycommand)
Try
myad.Fill(mydtb)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim drow As DataRow = mydtb.NewRow()
drow("id") = 1234
drow("section") = 1
mydtb.Rows.Add(drow)
Dim mycb As New OleDbCommandBuilder(myad)
AddHandler myad.RowUpdating, New
OleDbRowUpdatingEventHandler(AddressOf OnRowUpdating)
Try
myad.Update(mydtb)
Catch ex As Exception
MsgBox(ex.Message)
End Try

DataGrid1.DataSource = mydtb

conn.Close()
End Sub

Private Sub OnRowUpdating(ByVal sender As Object, ByVal args As
OleDbRowUpdatingEventArgs)
If args.StatementType = StatementType.Insert Then
Dim p As OleDbCommand = args.Command
Stop
'p.ExecuteNonQuery()
End If
End Sub
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Paul Clement
On Fri, 27 Aug 2004 05:07:03 -0700, "James" <Click here to reveal e-mail address> wrote:

¤ Try the following code.
¤
¤ The datasouce is MS access file, and the table abc has only two columns:
¤ 1. ID (integer) key
¤ 2. section (integer) non-unique
¤
¤ And try the following code would cause an exception saying that "syntax
¤ error in insert statement" during the myad.Update(mydtb) (I'm sure that it's
¤ not the key problem, there's nothing at all in the table abc in the MDB file)
¤
¤ if i changed the column 2 name ("section“) to another one in the datasouce
¤ (MDB file), let's say "num", the following code would work properly.
¤
¤ So I'm very confused!! Any help woul d be appreciated.
¤
¤
¤ VB. NET code
¤
¤ Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
¤ Source=C:\abc.mdb; Jet OLEDB:Database Password="
¤
¤ Private Sub initdb(ByRef conn As OleDbConnection)
¤ conn = New OleDbConnection(connStr)
¤ conn.Open()
¤ End Sub
¤
¤ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
¤ System.EventArgs) Handles Button1.Click
¤ Dim conn As OleDbConnection
¤ Dim mydtb As New DataTable
¤ initdb(conn)
¤ Dim mycommand As OleDbCommand = New OleDbCommand("select * from
¤ abc", conn)
¤
¤ Dim myad As OleDbDataAdapter = New OleDbDataAdapter(mycommand)
¤ Try
¤ myad.Fill(mydtb)
¤ Catch ex As Exception
¤ MsgBox(ex.Message)
¤ End Try
¤ Dim drow As DataRow = mydtb.NewRow()
¤ drow("id") = 1234
¤ drow("section") = 1

The field name you are using "section" is a Microsoft Jet reserved word. If must be enclosed within
brackets when referenced in a SQL statement.

List of Microsoft Jet 4.0 reserved words
http://support.microsoft.com/default.aspx?scid=kb;en-us;321266

Paul ~~~ Click here to reveal e-mail address
Microsoft MVP (Visual Basic)
Reply to this message...
Vote that this is a GOOD answer...
 
New BootFX DBGet build available
Twitter and Snow… simple #uksnow
 
 
System.Data.DataRow
System.Data.DataTable
System.Data.OleDb.OleDbCommand
System.Data.OleDb.OleDbCommandBuilder
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbDataAdapter
System.Data.OleDb.OleDbRowUpdatingEventArgs
System.Data.OleDb.OleDbRowUpdatingEventHandler
System.Data.StatementType
System.EventArgs
System.Object




Ad
BootFX
Reliable and powerful .NET application framework.
Looking to invest in a major software project? Technical and commercial advice available here.
Other Helpful Sites
MBR 247
Topaz Filer
SharePoint Email Filing
Software Advisory Services
 
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734