473,749 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update command OledbDataAdapte r problem

I made nova oledbdataadapte r select update insert and delete command and
connection veza. dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to Form2. The
select command works fine, but when I change the data and call update
command I get a syntax error:

System.Data.Ole Db.OleDbExcepti on was unhandled
ErrorCode=-2147217900
Message="Syntax error in UPDATE statement."
Source="Microso ft JET Database Engine"
StackTrace:
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atusErrors(RowU pdatedEventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atus(RowUpdated EventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.UpdateFromDa taTable(DataTab le
dataTable, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 272
at Diplomski1.Form 2.Table1Binding NavigatorSaveIt em_Click(Object
sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 8
at System.Windows. Forms.ToolStrip Item.RaiseEvent (Object key,
EventArgs e)
at System.Windows. Forms.ToolStrip Button.OnClick( EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleClic k(EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleMous eUp(MouseEventA rgs e)
at System.Windows. Forms.ToolStrip Item.FireEventI nteractive(Even tArgs
e, ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip Item.FireEvent( EventArgs e,
ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip .OnMouseUp(Mous eEventArgs mea)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.ToolStrip .WndProc(Messag e& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

The procedure cod is this:

Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim SelectCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim UpdateCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim InsertCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim DeleteCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Table", ComboBox1.Text)

veza.Open()

For i = 0 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt - 1
tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(0).Columns. Item(i).ColumnN ame,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i
nova.TableMappi ngs.Add(tableMa pping)

nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True

SelectCom.Conne ction = veza
SelectCom.Comma ndType = CommandType.Tex t
SelectCom.Comma ndText = "SELECT * FROM " & nova1

UpdateCom.Conne ction = veza
UpdateCom.Comma ndType = CommandType.Tex t
UpdateCom.Comma ndText = "UPDATE " & nova1 & " SET Broj iksice=?,
Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Current,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj
iksice", OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion. Original, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Current, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Prezime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Current, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "ime", DataRowVersion. Original, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Current,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj
indeksa", OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
True, CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion. Original, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Current,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj
pohadjanja", OleDb.OleDbType .Integer, 0,
System.Data.Par ameterDirection .Input, True, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion. Original, Nothing))
For i = 5 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt - 1
UpdateCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(0). Columns.Item(i) .ColumnName,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i

InsertCom.Conne ction = veza
InsertCom.Comma ndType = CommandType.Tex t
InsertCom.Comma ndText = "INSERT INTO " & nova1 & " (Broj iksice,
Prezime, Ime, Broj indeksa, " & _
"Broj pohadjanja) VALUES (?,?,?,?,?)"
InsertCom.Param eters.Add("Broj iksice", OleDb.OleDbType .Double, 0,
"Broj iksice")
InsertCom.Param eters.Add("Prez ime", OleDb.OleDbType .WChar, 0,
"Prezime")
InsertCom.Param eters.Add("Ime" , OleDb.OleDbType .WChar, 0, "Ime")
InsertCom.Param eters.Add("Broj indeksa", OleDb.OleDbType .WChar, 0,
"Broj indeksa")
InsertCom.Param eters.Add("Broj pohadjanja", OleDb.OleDbType .Integer,
0, "Broj pohadjanja")
For i = 5 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt - 1
InsertCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(0). Columns.Item(i) .ColumnName,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i

DeleteCom.Conne ction = veza
DeleteCom.Comma ndType = CommandType.Tex t
DeleteCom.Comma ndText = "UPDATE " & nova1 & " SET Broj iksice=?,
Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
DeleteCom.Param eters.Add("Broj iksice", OleDb.OleDbType .Double, 0,
"Broj iksice")
DeleteCom.Param eters.Add("Prez ime", OleDb.OleDbType .WChar, 0,
"Prezime")
DeleteCom.Param eters.Add("Ime" , OleDb.OleDbType .WChar, 0, "Ime")
DeleteCom.Param eters.Add("Broj indeksa", OleDb.OleDbType .WChar, 0,
"Broj indeksa")
DeleteCom.Param eters.Add("Broj pohadjanja", OleDb.OleDbType .Integer,
0, "Broj pohadjanja")
For i = 5 To Form2.Studenti1 Data.Tables.Ite m(0).Columns.Co unt - 1
DeleteCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(0). Columns.Item(i) .ColumnName,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(0).Columns.It em(i).ColumnNam e)
Next i

nova.SelectComm and = SelectCom
nova.UpdateComm and = UpdateCom
nova.DeleteComm and = DeleteCom
nova.InsertComm and = InsertCom

If nova2 = "Fill" Then

nova.Fill(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)))

End If

If nova2 = "Update" Then
nova.Update(For m2.Studenti1Dat a.Tables.Item(I ndex(ComboBox1. Text)))
End If
veza.Close()

End Sub

Index(tablename ) is a function that returns index of the table with
specified tablename.
Program stops executing on green marked text and I get a syntax error.
Where is the syntax error?
Please help....!!!!
Jan 21 '07 #1
2 2931
"explode" <ur**@mzos.hrsc hrieb
I made nova oledbdataadapte r select update insert and delete command and
connection veza. dataset is Studenti1data, I made it by the new data
source wizard,and made datagridview and bindingsource draging Table1 to
Form2. The select command works fine, but when I change the data and call
update command I get a syntax error:
In the SQL, put field names that contain blanks into brackets:
"...[Broj iksice]..."

It also seems that you are setting many more parameters for the
UpdateCommand than there are available. I count six "?" in the SQL but you
set some more.
Armin
Jan 21 '07 #2
Thank you! this was helpfull!
Jan 23 '07 #3

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

Similar topics

1
5090
by: Bennett Haselton | last post by:
Suppose I add a new row to a table in a dataset, and then I use an OleDbDataAdapter to add that new row to a SQL Server database using OleDbDataAdapter.Update(), as in the following code: dsLocalDataSet.user_postRow newRow = dsLocalDataSet1.user_post.Newuser_postRow(); newRow.post_text = this.lblHiddenMessageStorage.Text; newRow.post_datetime = System.DateTime.Now; dsLocalDataSet1.user_post.Adduser_postRow(newRow);...
4
2147
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
4
1834
by: William | last post by:
After much frustration I was able to update my data store via code only. Using the data adapter was the only way I was able to set up all the objects written in my code. Basically, I cheated by creating an adapter and then copy, paste, modify it's code to suite my needs. This was the end result: Private sub updateTable( ) Dim myData As DataSet 'Command is a form level oledbcommand object Dim Adapter1 As New OleDbDataAdapter(Command)
4
1494
by: William LaMartin | last post by:
In the past, I have filled a datagrid with data from an Access database table using a data adapter and dataset, where I used the OleDbCommandBuilder to have the program create the insert, delete and update commands automatically for the dataadapter. I think those database tables had no more than 10 or 12 fields. Then to save the changes in the datagrid to the database, I simply evoked the dataadapter update command. No problems. ...
8
2696
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
4
2313
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
15
1816
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders) ' Save any changes.
2
2338
by: Scotty | last post by:
I get stuck to write an update, insert and delete command, i am looking for some help to start Whats the best way to update 2 tables toe the database (Access) below my code used to load my data.(2 tables) Do someone has a good sample code to help me? Many thanks in advance, Marc.
13
8880
by: Terry Olsen | last post by:
I'm using OleDb to connect with an Access Database. I have anywhere from 10 to over 100 records that I need to either INSERT if the PK doesn't exist or UPDATE if the PK does exist, all in a single transaction. Does anyone have an SQL statement I can throw at it that would accomplish this? If I can't figure out how to do it, I'm going to have to send two discreet SQL commands for each record which will take infinitely longer than a...
0
8997
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
9568
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
9389
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
9335
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,...
1
6801
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
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
3320
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
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
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.