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

B

barret bonden

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
 
C

Cor Ligthert[MVP]

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
 
B

barret bonden

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 (?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top