473,415 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

Update command OledbDataAdapter problem

I made nova oledbdataadapter 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.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message="Syntax error in UPDATE statement."
Source="Microsoft JET Database Engine"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable
dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 272
at Diplomski1.Form2.Table1BindingNavigatorSaveItem_Cl ick(Object
sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 8
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key,
EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs
e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.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.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim SelectCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim UpdateCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim InsertCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim DeleteCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Table", ComboBox1.Text)

veza.Open()

For i = 0 To Form2.Studenti1Data.Tables.Item(0).Columns.Count - 1
tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(0).Columns.Item(i).ColumnName,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i
nova.TableMappings.Add(tableMapping)

nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True

SelectCom.Connection = veza
SelectCom.CommandType = CommandType.Text
SelectCom.CommandText = "SELECT * FROM " & nova1

UpdateCom.Connection = veza
UpdateCom.CommandType = CommandType.Text
UpdateCom.CommandText = "UPDATE " & nova1 & " SET Broj iksice=?,
Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Current,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
iksice", OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Original, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Current, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Current, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "ime", DataRowVersion.Original, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Current,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
indeksa", OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
True, CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion.Original, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Current,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
pohadjanja", OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion.Original, Nothing))
For i = 5 To Form2.Studenti1Data.Tables.Item(0).Columns.Count - 1
UpdateCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(0).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i

InsertCom.Connection = veza
InsertCom.CommandType = CommandType.Text
InsertCom.CommandText = "INSERT INTO " & nova1 & " (Broj iksice,
Prezime, Ime, Broj indeksa, " & _
"Broj pohadjanja) VALUES (?,?,?,?,?)"
InsertCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0,
"Broj iksice")
InsertCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0,
"Prezime")
InsertCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
InsertCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0,
"Broj indeksa")
InsertCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer,
0, "Broj pohadjanja")
For i = 5 To Form2.Studenti1Data.Tables.Item(0).Columns.Count - 1
InsertCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(0).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i

DeleteCom.Connection = veza
DeleteCom.CommandType = CommandType.Text
DeleteCom.CommandText = "UPDATE " & nova1 & " SET Broj iksice=?,
Prezime=?, Ime=?, Broj indeksa=?, Broj pohadjanja=? " & _
"WHERE Broj iksice=?"
DeleteCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0,
"Broj iksice")
DeleteCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0,
"Prezime")
DeleteCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
DeleteCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0,
"Broj indeksa")
DeleteCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer,
0, "Broj pohadjanja")
For i = 5 To Form2.Studenti1Data.Tables.Item(0).Columns.Count - 1
DeleteCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(0).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(0).Columns.Item(i) .ColumnName)
Next i

nova.SelectCommand = SelectCom
nova.UpdateCommand = UpdateCom
nova.DeleteCommand = DeleteCom
nova.InsertCommand = InsertCom

If nova2 = "Fill" Then

nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))

End If

If nova2 = "Update" Then
nova.Update(Form2.Studenti1Data.Tables.Item(Index( 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 2896
"explode" <ur**@mzos.hrschrieb
I made nova oledbdataadapter 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
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: ...
4
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...
4
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...
4
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...
8
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. ...
4
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,...
15
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...
2
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...
13
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
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...

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.