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 2269
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |