PC Review


Reply
Thread Tools Rate Thread

I can't even KISS ! 'Syntax error in INSERT INTO statement

 
 
barret bonden
Guest
Posts: n/a
 
      20th Apr 2009
Trying to teach myself ADO.NET. Here is the most simple example of a hand
coded use of ADO.NET I could find
(from a SAMS book)

The Access.MDB is OK, and this code does pull up records from it. It fails,
however, on saving with "Syntax error in INSERT INTO statement."
when it hits : m_daDatatadapter.Update(m_dtContacts) .

If anyone can point me to another simple hand coded example I can study and
play with I'd be much obliged.

Public Class Form1
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDatatadapter As New OleDb.OleDbDataAdapter
Private m_cdCommandbuilder As OleDb.OleDbCommandBuilder
Private m_dtContacts As New DataTable
Private m_rowPosition As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_cnADONetConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test.mdb;"
m_cnADONetConnection.Open()

m_daDatatadapter = New OleDb.OleDbDataAdapter("select * from test",
m_cnADONetConnection)

m_cdCommandbuilder = (New
OleDb.OleDbCommandBuilder(m_daDatatadapter))

m_daDatatadapter.Fill(m_dtContacts)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = m_dtContacts.Rows(m_rowPosition)("last").ToString

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim nr As DataRow = m_dtContacts.NewRow()
nr("last") = TextBox1.Text
'nr("first") = TextBox2.Text
m_dtContacts.Rows.Add(nr)

' ERROR HERE
m_daDatatadapter.Update(m_dtContacts) ' Syntax error in
INSERT INTO statement.



End sub


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      20th Apr 2009
Barret,

It can be that there are more fields in your row then what you are now
updating.
By instance, do you use a non autoidentifier key
Have you fields that cannot be null in the database
You use the Select * you know, you can start by selecting only those fields
which you need.

Cor

"barret bonden" <(E-Mail Removed)> wrote in message
news:49ec9d4a$0$5895$(E-Mail Removed)...
> Trying to teach myself ADO.NET. Here is the most simple example of a hand
> coded use of ADO.NET I could find
> (from a SAMS book)
>
> The Access.MDB is OK, and this code does pull up records from it. It
> fails, however, on saving with "Syntax error in INSERT INTO statement."
> when it hits : m_daDatatadapter.Update(m_dtContacts) .
>
> If anyone can point me to another simple hand coded example I can study
> and play with I'd be much obliged.
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Private m_cnADONetConnection As New OleDb.OleDbConnection
> Private m_daDatatadapter As New OleDb.OleDbDataAdapter
> Private m_cdCommandbuilder As OleDb.OleDbCommandBuilder
> Private m_dtContacts As New DataTable
> Private m_rowPosition As Integer = 0
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> m_cnADONetConnection.ConnectionString =
> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=c:\test.mdb;"
> m_cnADONetConnection.Open()
>
> m_daDatatadapter = New OleDb.OleDbDataAdapter("select * from test",
> m_cnADONetConnection)
>
> m_cdCommandbuilder = (New
> OleDb.OleDbCommandBuilder(m_daDatatadapter))
>
> m_daDatatadapter.Fill(m_dtContacts)
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> TextBox1.Text = m_dtContacts.Rows(m_rowPosition)("last").ToString
>
> End Sub
>
> Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button4.Click
> Dim nr As DataRow = m_dtContacts.NewRow()
> nr("last") = TextBox1.Text
> 'nr("first") = TextBox2.Text
> m_dtContacts.Rows.Add(nr)
>
> ' ERROR HERE
> m_daDatatadapter.Update(m_dtContacts) ' Syntax error in
> INSERT INTO statement.
>
>
>
> End sub
>


 
Reply With Quote
 
barret bonden
Guest
Posts: n/a
 
      20th Apr 2009
Cor:

I trimmed the SQL statement to just one field and tested and then took out
the key autonumber field I had in the table. I have no
fields that cannot be null.

I get the same error.

I get " in order to evaluate an indexed property , the property must be
qualified and the arguments must be explicitly supplied."

This is an Access 2003 MDB running on Windows 7, using VB 2008 Express
Edition. I've put back in the autonumber key to continue testing, as I
believe I need it (?)



"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Barret,
>
> It can be that there are more fields in your row then what you are now
> updating.
> By instance, do you use a non autoidentifier key
> Have you fields that cannot be null in the database
> You use the Select * you know, you can start by selecting only those
> fields which you need.
>
> Cor
>
> "barret bonden" <(E-Mail Removed)> wrote in message
> news:49ec9d4a$0$5895$(E-Mail Removed)...
>> Trying to teach myself ADO.NET. Here is the most simple example of a hand
>> coded use of ADO.NET I could find
>> (from a SAMS book)
>>
>> The Access.MDB is OK, and this code does pull up records from it. It
>> fails, however, on saving with "Syntax error in INSERT INTO statement."
>> when it hits : m_daDatatadapter.Update(m_dtContacts) .
>>
>> If anyone can point me to another simple hand coded example I can study
>> and play with I'd be much obliged.
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>> Private m_cnADONetConnection As New OleDb.OleDbConnection
>> Private m_daDatatadapter As New OleDb.OleDbDataAdapter
>> Private m_cdCommandbuilder As OleDb.OleDbCommandBuilder
>> Private m_dtContacts As New DataTable
>> Private m_rowPosition As Integer = 0
>> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>> m_cnADONetConnection.ConnectionString =
>> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>> "Data Source=c:\test.mdb;"
>> m_cnADONetConnection.Open()
>>
>> m_daDatatadapter = New OleDb.OleDbDataAdapter("select * from
>> test", m_cnADONetConnection)
>>
>> m_cdCommandbuilder = (New
>> OleDb.OleDbCommandBuilder(m_daDatatadapter))
>>
>> m_daDatatadapter.Fill(m_dtContacts)
>> End Sub
>>
>> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button1.Click
>> TextBox1.Text = m_dtContacts.Rows(m_rowPosition)("last").ToString
>>
>> End Sub
>>
>> Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button4.Click
>> Dim nr As DataRow = m_dtContacts.NewRow()
>> nr("last") = TextBox1.Text
>> 'nr("first") = TextBox2.Text
>> m_dtContacts.Rows.Add(nr)
>>
>> ' ERROR HERE
>> m_daDatatadapter.Update(m_dtContacts) ' Syntax error in
>> INSERT INTO statement.
>>
>>
>>
>> End sub
>>

>



 
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
Syntax error in INSERT INTO statement. vb.net Ben Microsoft ADO .NET 1 16th Jul 2007 04:08 PM
Syntax error in Insert Into statement =?Utf-8?B?U0w=?= Microsoft Access Queries 6 17th Aug 2005 09:22 PM
Syntax error in INSERT INTO statement =?Utf-8?B?U2FuZ2Vl?= Microsoft Access Forms 0 29th Jun 2005 07:35 PM
Syntax error in INSERT INTO statement =?Utf-8?B?Qm9nZ2ll?= Microsoft C# .NET 2 5th Aug 2004 11:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:26 AM.