2016-11-23 39 views
-1

当我使用UPDATE查询来更新一个值NUMBER数据类型字段,我得到的数据类型不匹配错误更新到数字数据类型由vb.net

我的代码:

com.CommandText = "UPDATE register SET [email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_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 [email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_reg,[email protected]_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

使用'Add',而不是'AddWithValue'和文本控件的文本转换为任何类型应该是 – Plutonix

+0

@之前参数也可能有帮助 – Aaron

+0

谢谢Aaron回答,但不工作 –

回答

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

+0

由于其工作 –

+0

请查看更新的答案,我给你一些关键点就 –

+0

YW和快乐编码 –