473,695 Members | 2,767 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 2927
"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
5084
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
2146
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
1830
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
1491
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
2692
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
2309
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
1810
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
2329
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
8870
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
8555
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8971
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...
0
8817
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
7651
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6484
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
5831
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
4336
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...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1970
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.