通过vb.net更新为数字数据类型

时间:2016-11-23 19:01:42

标签: vb.net ms-access

当我使用UPDATE查询将值更新为NUMBER数据类型字段时,我得到数据类型不匹配错误

我的代码:

com.CommandText = "UPDATE register SET price_reg=@price_reg,rprice_reg=@rprice_reg,ipprice_reg=@ipprice_reg,mprice_reg=@mprice_reg,totalp_reg=@totalp_reg,operatormali_reg=@operatormali_reg,noedaryaft_reg=@noedaryaft_reg,datedaryaft_reg=@datedaryaft_reg WHERE id_reg='" & Label58.Text & "' "

    com.Parameters.AddWithValue("@price_reg", TextBox12.Text)
    com.Parameters.AddWithValue("@rprice_reg", TextBox11.Text)
    com.Parameters.AddWithValue("@ipprice_reg", TextBox13.Text)
    com.Parameters.AddWithValue("@mprice_reg", TextBox14.Text)
    com.Parameters.AddWithValue("@totalp_reg", TextBox15.Text)
    com.Parameters.AddWithValue("@operatormali_reg", username)
    com.Parameters.AddWithValue("@noedaryaft_reg", ComboBox1.Text)
    com.Parameters.AddWithValue("@datedaryaft_reg", TextBox16.Text)
    com.ExecuteNonQuery()

5第一个参数是我的访问数据库中的NUMBER数据类型

我也尝试发送参数:

com.Parameters.AddWithValue("@price_reg", convert.toint32(TextBox12.Text))

我也试试这个:

com.Parameters.AddWithValue("@price_reg", Cdec(TextBox12.Text))

我也尝试添加:

 com.CommandText = "UPDATE register SET price_reg=@price_reg,rprice_reg=@rprice_reg,ipprice_reg=@ipprice_reg,mprice_reg=@mprice_reg,totalp_reg=@totalp_reg,operatormali_reg=@operatormali_reg,noedaryaft_reg=@noedaryaft_reg,datedaryaft_reg=@datedaryaft_reg WHERE id_reg='" & Label58.Text & "' "

    com.Parameters.Add("@price_reg", OleDbType.Integer)
    com.Parameters("@price_reg").Value = CInt(TextBox12.Text)

    com.Parameters.Add("@rprice_reg", OleDbType.Integer)
    com.Parameters("@rprice_reg").Value = CInt(TextBox11.Text)

    com.Parameters.Add("@ipprice_reg", OleDbType.Integer)
    com.Parameters("@ipprice_reg").Value = CInt(TextBox13.Text)

    com.Parameters.Add("@mprice_reg", OleDbType.Integer)
    com.Parameters("@mprice_reg").Value = CInt(TextBox14.Text)

    com.Parameters.Add("@totalp_reg", OleDbType.Integer)
    com.Parameters("@totalp_reg").Value = CInt(TextBox15.Text)

    com.Parameters.AddWithValue("@operatormali_reg", username)
    com.Parameters.AddWithValue("@noedaryaft_reg", ComboBox1.Text)
    com.Parameters.AddWithValue("@datedaryaft_reg", TextBox16.Text)
    com.ExecuteNonQuery()

但同样的错误

错误消息:



System.Data.OleDb.OleDbException was unhandled
  ErrorCode=-2147217913
  Message="Data type mismatch in criteria expression."
  Source="Microsoft JET Database Engine"
  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(Object& executeResult)    at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)    at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)    at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()    at asiatech_managment.Form1.ToolStripButton23_Click(Object sender, EventArgs e) in C:\Users\pc1\Documents\Visual Studio 2008\Projects\asiatech-managment\asiatech-managment\Form1.vb:line 360    at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)    at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)    at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)    at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)    at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)    at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)    at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs 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(Message& m)    at System.Windows.Forms.ToolStrip.WndProc(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 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()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)    at asiatech_managment.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 




感谢您的回答

1 个答案:

答案 0 :(得分:0)

错误说

Message="Data type mismatch in criteria expression."

我的问题是id_reg的数据类型是什么?是INT吗?如果是,那就做这样的事情。

改变你的

WHERE id_reg='" & Label58.Text & "' "

WHERE id_reg=" & Label58.Text

enter image description here