您好我正在尝试使用VB.net更新访问数据库,并且收到语法错误。除了这个,我程序中的其他所有内容都有效!
System.Data.OleDb.OleDbException未处理ErrorCode = -2147217900 HResult = -2147217900消息= UPDATE语句中的语法错误。 Source = Microsoft Office Access数据库引擎StackTrace:at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams,Object& executeResult)at System.Data.OleDb.OleDbCommand.ExecuteCommandText(对象&安培; executeResult)at System.Data.OleDb.OleDbCommand.ExecuteCommand(的CommandBehavior 行为,对象& executeResult)at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(的CommandBehavior 行为,String方法)at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()at WindowsApplication3.Form2.AddAddButton_Click(Object sender,EventArgs e)在C:\ Users \ Andrew \ Documents \ Visual Studio中 2013 \ Projects \ WindowsApplication3 \ WindowsApplication3 \ Form2.vb:第83行 在System.Windows.Forms.Control.OnClick(EventArgs e)at System.Windows.Forms.Button.OnClick(EventArgs e)at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)at at System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons 按钮,Int32点击)at System.Windows.Forms.Control.WndProc(Message& m)at System.Windows.Forms.ButtonBase.WndProc(Message& m)at System.Windows.Forms.Button.WndProc(Message& m)at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr) hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr的 dwComponentID,Int32 reason,Int32 pvLoopData)at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(的Int32 reason,ApplicationContext context)at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(的Int32 reason,ApplicationContext context)at System.Windows.Forms.Application.Run(ApplicationContext context)at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(字符串[] WindowsApplication3.My.MyApplication.Main(String []上的commandLine) Args)in 17d14f5c-a337-4978-8281-53493378c1071.vb:第81行 System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)在System.AppDomain.ExecuteAssembly(String assemblyFile, 证据assemblySecurity,String [] args)at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态)at System.Threading.ThreadHelper.ThreadStart()InnerException:
Private Sub AddAddButton_Click(sender As Object, e As EventArgs) Handles AddAddButton.Click
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\*****************************;Jet OLEDB:Database Password=*********;")
Dim insertsql As String
Try
insertsql = "UPDATE RepairOrders SET ROOther = @Other, ROJobType = @Type, SET ROJobTime = @Time, SET RODelPicDate = @DelPic WHERE RONo = @JobNo"
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(insertsql, conn)
cmd.Parameters.AddWithValue("@Other", AddOtherText.Text)
cmd.Parameters.AddWithValue("@Type", AddTypeCombo.SelectedValue)
If AddTimeCombo.Text = "AM" Then
cmd.Parameters.AddWithValue("@Time", Convert.ToInt32("1"))
Else
cmd.Parameters.AddWithValue("@Time", Convert.ToInt32("2"))
End If
cmd.Parameters.AddWithValue("@Time", Convert.ToInt32(AddTimeCombo.SelectedValue))
cmd.Parameters.AddWithValue("@DelPic", AddDatePick.Value.Date.ToString)
cmd.Parameters.AddWithValue("@JobNo", Convert.ToInt32(AddJobText.Text))
conn.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("Booking Added!")
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
我在代码中隐藏了一些敏感信息。请帮我确认一下这个问题。谢谢你:)
答案 0 :(得分:0)
您的查询中有多个SET
。将其更改为
insertsql = "UPDATE RepairOrders SET ROOther = @Other,
ROJobType = @Type, ROJobTime = @Time, RODelPicDate = @DelPic WHERE RONo = @JobNo"