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.OleDbConnection = New OleDb.OleDbConnection
Dim cns As String = ""
Dim mDBN As String = "C:\BNM.MDB"
Dim cCON As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mDBN
& ";Persist Security Info = False"
Connection.ConnectionString = cCON
Connection.Open()
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql,
Connection)
Dim Cmand As New OleDb.OleDbCommand
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
Dim Dataroww As DataRow
DAdapter.Fill(DataSets, "Numbers")
CBuild = New OleDb.OleDbCommandBuilder(DAdapter)
'create pkey
With DataSets.Tables("Numbers")
..PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'create a select command with all parameters
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Dataroww = DataSets.Tables("Numbers").NewRow
Dataroww.BeginEdit()
Dataroww("Number") = "9999999"
Dataroww("Name") = "KJHGFDSA"
Dataroww("Block") = True
Dataroww.EndEdit()
DataSets.Tables("Numbers").Rows.Add(Dataroww)
DAdapter.Update(DataSets, "Numbers") ' errors out here insert error
DataSets.AcceptChanges() 4 2272
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****************@TK2MSFTNGP02.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.OleDbConnection = New OleDb.OleDbConnection
Dim cns As String = ""
Dim mDBN As String = "C:\BNM.MDB"
Dim cCON As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
mDBN & ";Persist Security Info = False"
Connection.ConnectionString = cCON
Connection.Open()
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql,
Connection)
Dim Cmand As New OleDb.OleDbCommand
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
Dim Dataroww As DataRow
DAdapter.Fill(DataSets, "Numbers")
CBuild = New OleDb.OleDbCommandBuilder(DAdapter)
'create pkey
With DataSets.Tables("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'create a select command with all parameters
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Dataroww = DataSets.Tables("Numbers").NewRow
Dataroww.BeginEdit()
Dataroww("Number") = "9999999"
Dataroww("Name") = "KJHGFDSA"
Dataroww("Block") = True
Dataroww.EndEdit()
DataSets.Tables("Numbers").Rows.Add(Dataroww)
DAdapter.Update(DataSets, "Numbers") ' errors out here insert error
DataSets.AcceptChanges()
AGGHHHHHHHHHH
WHY did the MicroSoft Example that I printed at 40 pages DID NOT say that?
AGGGGGGGGGGGHHHHHHHHHHH
Thanks.......
Hitting myself, hitting myself, hitting myself...............
"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:eA**************@TK2MSFTNGP02.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****************@TK2MSFTNGP02.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.OleDbConnection = New OleDb.OleDbConnection
Dim cns As String = ""
Dim mDBN As String = "C:\BNM.MDB"
Dim cCON As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mDBN & ";Persist Security Info = False"
Connection.ConnectionString = cCON
Connection.Open()
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql, Connection)
Dim Cmand As New OleDb.OleDbCommand
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
Dim Dataroww As DataRow
DAdapter.Fill(DataSets, "Numbers")
CBuild = New OleDb.OleDbCommandBuilder(DAdapter)
'create pkey
With DataSets.Tables("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'create a select command with all parameters
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Dataroww = DataSets.Tables("Numbers").NewRow
Dataroww.BeginEdit()
Dataroww("Number") = "9999999"
Dataroww("Name") = "KJHGFDSA"
Dataroww("Block") = True
Dataroww.EndEdit()
DataSets.Tables("Numbers").Rows.Add(Dataroww)
DAdapter.Update(DataSets, "Numbers") ' errors out here insert error
DataSets.AcceptChanges()
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****************@TK2MSFTNGP04.phx.gbl...
AGGHHHHHHHHHH
WHY did the MicroSoft Example that I printed at 40 pages DID NOT say that?
AGGGGGGGGGGGHHHHHHHHHHH
Thanks.......
Hitting myself, hitting myself, hitting myself...............
"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:eA**************@TK2MSFTNGP02.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****************@TK2MSFTNGP02.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.OleDbConnection = New OleDb.OleDbConnection
Dim cns As String = ""
Dim mDBN As String = "C:\BNM.MDB"
Dim cCON As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mDBN & ";Persist Security Info = False"
Connection.ConnectionString = cCON
Connection.Open()
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql, Connection)
Dim Cmand As New OleDb.OleDbCommand
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
Dim Dataroww As DataRow
DAdapter.Fill(DataSets, "Numbers")
CBuild = New OleDb.OleDbCommandBuilder(DAdapter)
'create pkey
With DataSets.Tables("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'create a select command with all parameters
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Dataroww = DataSets.Tables("Numbers").NewRow
Dataroww.BeginEdit()
Dataroww("Number") = "9999999"
Dataroww("Name") = "KJHGFDSA"
Dataroww("Block") = True
Dataroww.EndEdit()
DataSets.Tables("Numbers").Rows.Add(Dataroww)
DAdapter.Update(DataSets, "Numbers") ' errors out here insert error
DataSets.AcceptChanges()
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("Number")}
End With
I don't see the sence for this one
DataSets.AcceptChanges()
This one is included in the DataAdapter Update, only if you use partial
updates you need it.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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)
{
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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: 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...
| |