473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Can't insrt in my table

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.ExecuteCommandTextE rrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(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.AppSett ings("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?


Nov 21 '05 #1
1 968
I found the problem. One of the field has the same name as one of the Access
reserve word but it is one that I didn't suspect at all (IDEntity...)when I
had the [] around IDEntity, my SQL string works

"Marc Robitaille" <ma*************@ars-solutions.caa> a écrit dans le
message de news: uf*************@TK2MSFTNGP15.phx.gbl...
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.ExecuteCommandTextE rrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(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.AppSett ings("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?


Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
1
by: Anna K. | last post by:
Hi Experts, I'm new to JavaScript and web-based apps development, so I'll tell you right off that I don't really know my way around it as of yet. I'm trying to create a code library set with...
19
by: davegb | last post by:
Have been trying, in my spare time, to create an Access db for the employees in my group for over a month. It surprised me when I read in the Access Bible that a relationship between the Primary...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.