M
Marc Robitaille
Hello,
I have a stange error and I don't know where to look at. I do multiple
insert in muliple table in my MDB databse. Everything work except from one
table. when the code execute I get this error:
Message "Syntax Error in the instruction INSERT INTO."
StackTrace " at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at NTiersConstructeur.Data.DataProviderOleDb.Execute(String SQL) in
C:\_DEV\NTiersConstructeur\Classe\DataProvider.vb:line 187" String
When I execute the sql string in my mdb, It's work!!!
Here is the sql string
INSERT INTO [Valeur] (IDEntity, [Name], [Description], [Version],
[TypeValue], [ReadWriteValue], [FieldNameValue]) VALUES (20, 'Valeur1', '',
'', 'String', 'ReadWrite', '' )
Here is the code that execute all the insert, update and delete SQL string
Private Function Execute(ByVal SQL As String) As Boolean
Try
Dim strConnectionString =
System.Configuration.ConfigurationSettings.AppSettings("OLEConnectionString")
Dim oConnection As New OleDbConnection
oConnection.ConnectionString = strConnectionString
oConnection.Open()
Dim oCommand As OleDbCommand
oCommand = New OleDbCommand(SQL, oConnection)
oCommand.CommandType = CommandType.Text
Dim oTransaction As OleDbTransaction
oTransaction = oConnection.BeginTransaction
oCommand.Transaction = oTransaction
Dim intResult As Integer = 0
intResult = oCommand.ExecuteNonQuery
Dim blnResult As Boolean = False
If intResult >= 0 Then
blnResult = True
End If
If blnResult Then
oTransaction.Commit()
Else
oTransaction.Rollback()
End If
oConnection.Close()
oConnection.Dispose()
oCommand.Dispose()
Return blnResult
Catch ex As ArgumentException
Catch ex As OleDbException
MsgBox(ex.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Can someone tell me what I am doing wrong? Is there an error in my sql
string? Why do I have this error only with one table and not from the
others?
I have a stange error and I don't know where to look at. I do multiple
insert in muliple table in my MDB databse. Everything work except from one
table. when the code execute I get this error:
Message "Syntax Error in the instruction INSERT INTO."
StackTrace " at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at NTiersConstructeur.Data.DataProviderOleDb.Execute(String SQL) in
C:\_DEV\NTiersConstructeur\Classe\DataProvider.vb:line 187" String
When I execute the sql string in my mdb, It's work!!!
Here is the sql string
INSERT INTO [Valeur] (IDEntity, [Name], [Description], [Version],
[TypeValue], [ReadWriteValue], [FieldNameValue]) VALUES (20, 'Valeur1', '',
'', 'String', 'ReadWrite', '' )
Here is the code that execute all the insert, update and delete SQL string
Private Function Execute(ByVal SQL As String) As Boolean
Try
Dim strConnectionString =
System.Configuration.ConfigurationSettings.AppSettings("OLEConnectionString")
Dim oConnection As New OleDbConnection
oConnection.ConnectionString = strConnectionString
oConnection.Open()
Dim oCommand As OleDbCommand
oCommand = New OleDbCommand(SQL, oConnection)
oCommand.CommandType = CommandType.Text
Dim oTransaction As OleDbTransaction
oTransaction = oConnection.BeginTransaction
oCommand.Transaction = oTransaction
Dim intResult As Integer = 0
intResult = oCommand.ExecuteNonQuery
Dim blnResult As Boolean = False
If intResult >= 0 Then
blnResult = True
End If
If blnResult Then
oTransaction.Commit()
Else
oTransaction.Rollback()
End If
oConnection.Close()
oConnection.Dispose()
oCommand.Dispose()
Return blnResult
Catch ex As ArgumentException
Catch ex As OleDbException
MsgBox(ex.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Can someone tell me what I am doing wrong? Is there an error in my sql
string? Why do I have this error only with one table and not from the
others?