error on adding record to database

C

Co

Hi All,

I'm trying to add a new record to an access database.
I have used this code before without problems and now it doesn't
work.
I get an error saying there is a syntax error in the INSERT statement:

Private Sub AddFolder2Database(ByVal iParent As Integer, ByVal
sFolderName As String)

conn.Open()
Dim sql As String = "SELECT * FROM Kabinet"
Dim strTable As String = "Kabinet"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim newRow As DataRow

Try
da.FillSchema(ds, SchemaType.Source, strTable)
newRow = ds.Tables(strTable).NewRow()
newRow("foldername") = sFolderName
newRow("parent-id") = iParent

'add the new row to the dataSet
ds.Tables(strTable).Rows.Add(newRow)

'sent the updated dataSet to the database
da.Update(ds, strTable)

Catch oException As OleDbException
MessageBox.Show(oException.Message)

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
conn.Close()

End Sub

Regards
Marco
The Netherlands
 
A

Armin Zingler

Co said:
Hi All,

I'm trying to add a new record to an access database.
I have used this code before without problems and now it doesn't
work.
I get an error saying there is a syntax error in the INSERT statement:

Examine the Exception object. It will probably give more error information.

Also try setting the OleDbCommandBuilder's QuotePrefix/Suffix properties to
"[" and "]".


Armin
 
C

Co

Co said:
I'm trying to add a new record to an access database.
I have used this code before without problems and now it doesn't
work.
I get an error saying there is a syntax error in the INSERT statement:

Examine the Exception object. It will probably give more error information.

Also try setting the OleDbCommandBuilder's QuotePrefix/Suffix properties to
"[" and "]".

Armin

The last sentence did it.
Thanks

Marco
 

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