PC Review


Reply
Thread Tools Rate Thread

Dataadapter produces error: Syntax error in INSERT INTO statement

 
 
William LaMartin
Guest
Posts: n/a
 
      2nd Jan 2006
The code below loads an Access table with one row. It then adds a row and
displays all this in a datagridview. So far so good.

But when I use the dataadapter's update command to update the database
table, I receive the following error:
Syntax error in INSERT INTO statement

The Insert statement as displayed by the debug,write line is:
INSERT INTO Main (Id, Interval, Tutor1, Tutor2) VALUES (?, ?, ?, ?), which
looks fine to me.

Where is the problem? The Commandbuilder should have no problems with this
simple setup.

The code:

Dim ds2 As New DataSet
Dim da2 As New Data.OleDb.OleDbDataAdapter
Dim dc As Data.OleDb.OleDbConnection = New OleDb.OleDbConnection
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Test2.mdb"
dc.Open()
Dim StrSQL As String = "SELECT * from Main"
Dim objCommand As New Data.OleDb.OleDbCommand(StrSQL, dc)
da2.SelectCommand = objCommand
Dim CB2 As Data.OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(da2)
Debug.Write("CB: " & CB2.GetInsertCommand.CommandText) 'What it
writes looks fine to me

da2.Fill(ds2, "Main")

Dim NewRow As DataRow = ds2.Tables(0).NewRow
NewRow.Item("ID") = 254
NewRow.Item("Interval") = 22
NewRow.Item("Tutor1") = "Joe"
NewRow.Item("Tutor2") = "Mary"
ds2.Tables(0).Rows.Add(NewRow)
Me.DataGridView1.DataSource = ds2.Tables(0)

MsgBox("Got this far")

da2.Update(ds2, "Main") 'Here is where the error occurs.


 
Reply With Quote
 
 
 
 
William LaMartin
Guest
Posts: n/a
 
      2nd Jan 2006
Problem solved.

The database had a keyword used in a field name. Once that was corrected,
then the update worked.

"William LaMartin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The code below loads an Access table with one row. It then adds a row and
> displays all this in a datagridview. So far so good.
>
> But when I use the dataadapter's update command to update the database
> table, I receive the following error:
> Syntax error in INSERT INTO statement
>
> The Insert statement as displayed by the debug,write line is:
> INSERT INTO Main (Id, Interval, Tutor1, Tutor2) VALUES (?, ?, ?, ?), which
> looks fine to me.
>
> Where is the problem? The Commandbuilder should have no problems with
> this simple setup.
>
> The code:
>
> Dim ds2 As New DataSet
> Dim da2 As New Data.OleDb.OleDbDataAdapter
> Dim dc As Data.OleDb.OleDbConnection = New OleDb.OleDbConnection
> dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=Test2.mdb"
> dc.Open()
> Dim StrSQL As String = "SELECT * from Main"
> Dim objCommand As New Data.OleDb.OleDbCommand(StrSQL, dc)
> da2.SelectCommand = objCommand
> Dim CB2 As Data.OleDb.OleDbCommandBuilder = New
> OleDb.OleDbCommandBuilder(da2)
> Debug.Write("CB: " & CB2.GetInsertCommand.CommandText) 'What it
> writes looks fine to me
>
> da2.Fill(ds2, "Main")
>
> Dim NewRow As DataRow = ds2.Tables(0).NewRow
> NewRow.Item("ID") = 254
> NewRow.Item("Interval") = 22
> NewRow.Item("Tutor1") = "Joe"
> NewRow.Item("Tutor2") = "Mary"
> ds2.Tables(0).Rows.Add(NewRow)
> Me.DataGridView1.DataSource = ds2.Tables(0)
>
> MsgBox("Got this far")
>
> da2.Update(ds2, "Main") 'Here is where the error occurs.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error in Insert Into statement Sanju Microsoft Access Form Coding 1 5th May 2008 07:49 AM
Run-time error 3134, Syntax error in INSERT INTO statement bchase Microsoft Access VBA Modules 2 16th Apr 2008 09:46 PM
Syntax Error - INSERT INTO Statement =?Utf-8?B?SmV6?= Microsoft Access VBA Modules 4 12th Jul 2007 11:58 AM
Syntax error in Insert Into statement =?Utf-8?B?U2hlbGw=?= Microsoft Access 7 12th Jan 2007 02:00 AM
syntax error in INSERT INTO statement William Microsoft ADO .NET 3 3rd Jun 2005 12:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.