473,795 Members | 3,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error in INSERT INTO statement

Maybe someone can help, my code works untill it gets to update when it tells
me Syntax error in INSERT INTO statement.
Thought this was automaticaly created according to MS.
Im lost, my code is below to copy and paste. Just change to your database,
tablename, fields to edit and sql.

AGGHHHHHH

thanks
Public Sub insertit(ByRef Msql As String)

Dim Connection As OleDb.OleDbConn ection = New OleDb.OleDbConn ection

Dim cns As String = ""

Dim mDBN As String = "C:\BNM.MDB "

Dim cCON As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mDBN
& ";Persist Security Info = False"

Connection.Conn ectionString = cCON

Connection.Open ()

Dim DAdapter As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter(Msql,
Connection)

Dim Cmand As New OleDb.OleDbComm and

Dim CBuild As New OleDb.OleDbComm andBuilder

Dim DataSets As New DataSet

Dim Dataroww As DataRow

DAdapter.Fill(D ataSets, "Numbers")

CBuild = New OleDb.OleDbComm andBuilder(DAda pter)

'create pkey

With DataSets.Tables ("Numbers")

..PrimaryKey = New DataColumn() {.Columns("Numb er")}

End With

'create a select command with all parameters

DAdapter.Insert Command = CBuild.GetInser tCommand()

Dataroww = DataSets.Tables ("Numbers").New Row

Dataroww.BeginE dit()

Dataroww("Numbe r") = "9999999"

Dataroww("Name" ) = "KJHGFDSA"

Dataroww("Block ") = True

Dataroww.EndEdi t()

DataSets.Tables ("Numbers").Row s.Add(Dataroww)

DAdapter.Update (DataSets, "Numbers") ' errors out here insert error

DataSets.Accept Changes()
Nov 18 '06 #1
4 2284
Hi,

Usually what causes this is one of the column names is a
keyword. To prevent the error you need to place the column name in [ ].

Instead of using a query like
Select * from MyTable

try using

Select [col1], [col2], [col3] from MyTable

The commandbuilder will use the col name is [ ] so you will not get the
error.

Ken
---------------------------
"Warex" <Ig************ @juno.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Maybe someone can help, my code works untill it gets to update when it
tells me Syntax error in INSERT INTO statement.
Thought this was automaticaly created according to MS.
Im lost, my code is below to copy and paste. Just change to your database,
tablename, fields to edit and sql.

AGGHHHHHH

thanks
Public Sub insertit(ByRef Msql As String)

Dim Connection As OleDb.OleDbConn ection = New OleDb.OleDbConn ection

Dim cns As String = ""

Dim mDBN As String = "C:\BNM.MDB "

Dim cCON As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
mDBN & ";Persist Security Info = False"

Connection.Conn ectionString = cCON

Connection.Open ()

Dim DAdapter As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter(Msql,
Connection)

Dim Cmand As New OleDb.OleDbComm and

Dim CBuild As New OleDb.OleDbComm andBuilder

Dim DataSets As New DataSet

Dim Dataroww As DataRow

DAdapter.Fill(D ataSets, "Numbers")

CBuild = New OleDb.OleDbComm andBuilder(DAda pter)

'create pkey

With DataSets.Tables ("Numbers")

.PrimaryKey = New DataColumn() {.Columns("Numb er")}

End With

'create a select command with all parameters

DAdapter.Insert Command = CBuild.GetInser tCommand()

Dataroww = DataSets.Tables ("Numbers").New Row

Dataroww.BeginE dit()

Dataroww("Numbe r") = "9999999"

Dataroww("Name" ) = "KJHGFDSA"

Dataroww("Block ") = True

Dataroww.EndEdi t()

DataSets.Tables ("Numbers").Row s.Add(Dataroww)

DAdapter.Update (DataSets, "Numbers") ' errors out here insert error

DataSets.Accept Changes()


Nov 18 '06 #2
AGGHHHHHHHHHH
WHY did the MicroSoft Example that I printed at 40 pages DID NOT say that?
AGGGGGGGGGGGHHH HHHHHHHH

Thanks.......

Hitting myself, hitting myself, hitting myself......... ......

"Ken Tucker [MVP]" <vb***@bellsout h.netwrote in message
news:eA******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

Usually what causes this is one of the column names is a
keyword. To prevent the error you need to place the column name in [ ].

Instead of using a query like
Select * from MyTable

try using

Select [col1], [col2], [col3] from MyTable

The commandbuilder will use the col name is [ ] so you will not get the
error.

Ken
---------------------------
"Warex" <Ig************ @juno.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Maybe someone can help, my code works untill it gets to update when it
tells me Syntax error in INSERT INTO statement.
Thought this was automaticaly created according to MS.
Im lost, my code is below to copy and paste. Just change to your
database, tablename, fields to edit and sql.

AGGHHHHHH

thanks
Public Sub insertit(ByRef Msql As String)

Dim Connection As OleDb.OleDbConn ection = New OleDb.OleDbConn ection

Dim cns As String = ""

Dim mDBN As String = "C:\BNM.MDB "

Dim cCON As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
mDBN & ";Persist Security Info = False"

Connection.Con nectionString = cCON

Connection.Ope n()

Dim DAdapter As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter(Msql,
Connection)

Dim Cmand As New OleDb.OleDbComm and

Dim CBuild As New OleDb.OleDbComm andBuilder

Dim DataSets As New DataSet

Dim Dataroww As DataRow

DAdapter.Fill( DataSets, "Numbers")

CBuild = New OleDb.OleDbComm andBuilder(DAda pter)

'create pkey

With DataSets.Tables ("Numbers")

.PrimaryKey = New DataColumn() {.Columns("Numb er")}

End With

'create a select command with all parameters

DAdapter.Inser tCommand = CBuild.GetInser tCommand()

Dataroww = DataSets.Tables ("Numbers").New Row

Dataroww.Begin Edit()

Dataroww("Numb er") = "9999999"

Dataroww("Name ") = "KJHGFDSA"

Dataroww("Bloc k") = True

Dataroww.EndEd it()

DataSets.Table s("Numbers").Ro ws.Add(Dataroww )

DAdapter.Updat e(DataSets, "Numbers") ' errors out here insert error

DataSets.Accep tChanges()



Nov 18 '06 #3
I'm sure Microsoft took it for granted, as most of us do.
I've gotten a little paranoid about it, myself.

Stop hitting yourself, you're going to cause a brain
tumor, and then you'll never get your work done. ;-)

Robin S.
------------------------------

"Warex" <Ig************ @juno.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
AGGHHHHHHHHHH
WHY did the MicroSoft Example that I printed at 40 pages DID NOT say that?
AGGGGGGGGGGGHHH HHHHHHHH

Thanks.......

Hitting myself, hitting myself, hitting myself......... ......

"Ken Tucker [MVP]" <vb***@bellsout h.netwrote in message
news:eA******** ******@TK2MSFTN GP02.phx.gbl...
>Hi,

Usually what causes this is one of the column names is a
keyword. To prevent the error you need to place the column name in [ ].

Instead of using a query like
Select * from MyTable

try using

Select [col1], [col2], [col3] from MyTable

The commandbuilder will use the col name is [ ] so you will not get the
error.

Ken
---------------------------
"Warex" <Ig************ @juno.comwrote in message
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>Maybe someone can help, my code works untill it gets to update when it
tells me Syntax error in INSERT INTO statement.
Thought this was automaticaly created according to MS.
Im lost, my code is below to copy and paste. Just change to your
database, tablename, fields to edit and sql.

AGGHHHHHH

thanks
Public Sub insertit(ByRef Msql As String)

Dim Connection As OleDb.OleDbConn ection = New OleDb.OleDbConn ection

Dim cns As String = ""

Dim mDBN As String = "C:\BNM.MDB "

Dim cCON As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
mDBN & ";Persist Security Info = False"

Connection.Co nnectionString = cCON

Connection.Op en()

Dim DAdapter As OleDb.OleDbData Adapter = New
OleDb.OleDbDa taAdapter(Msql, Connection)

Dim Cmand As New OleDb.OleDbComm and

Dim CBuild As New OleDb.OleDbComm andBuilder

Dim DataSets As New DataSet

Dim Dataroww As DataRow

DAdapter.Fill (DataSets, "Numbers")

CBuild = New OleDb.OleDbComm andBuilder(DAda pter)

'create pkey

With DataSets.Tables ("Numbers")

.PrimaryKey = New DataColumn() {.Columns("Numb er")}

End With

'create a select command with all parameters

DAdapter.Inse rtCommand = CBuild.GetInser tCommand()

Dataroww = DataSets.Tables ("Numbers").New Row

Dataroww.Begi nEdit()

Dataroww("Num ber") = "9999999"

Dataroww("Nam e") = "KJHGFDSA"

Dataroww("Blo ck") = True

Dataroww.EndE dit()

DataSets.Tabl es("Numbers").R ows.Add(Datarow w)

DAdapter.Upda te(DataSets, "Numbers") ' errors out here insert error

DataSets.Acce ptChanges()




Nov 18 '06 #4
Warex,

Are you aware that you use some not needed code.
(inline everytime under your code)
>
Dim cns As String = ""
the = "" is not needed in VB.Net
However you don't use that string
'create pkey
With DataSets.Tables ("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Numb er")}
End With
I don't see the sence for this one
DataSets.Accept Changes()
This one is included in the DataAdapter Update, only if you use partial
updates you need it.

Cor
Nov 19 '06 #5

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

Similar topics

6
2216
by: Gérard Leclercq | last post by:
ACCESS First fields are TEXT, last 2 are Numbers The name of the fields are correct. Dim MyConn Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/xdata/sc.mdb")
4
18059
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out on me for some reason. The Summary field is pulled from a Rich Text Editor that allows HTML formatting and appears to be the culprit, but I just can't seem to figure out why. Any guidance is greatly appreciated. I'm connecting to an Access...
3
4774
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
7
6677
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
2
1603
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
2823
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write so as to check that it is working correctly it displays just fine. However, whenever I include the password field in one of the SQL INSERT statement's fields I get the following error:
3
2502
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
5
2146
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
2
2817
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the data with a simple loop. I am using OleDbCommandbuilder to build the INSERT command but for some reason when it gets to a particular table in the database it errors out giving me "Syntax Error in INSERT INTO Statement". The cmmandbuilder built...
6
6006
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into it has been troublesome to say the least. My ASP.NET script is supposed to execute an INSERT INTO statement in order to add a user to the database. Here is a sample:
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.