error on adding record to database

  • Thread starter Thread starter Co
  • Start date Start date
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
 
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
 
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
 
Back
Top