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....!!!!