Ali sync Ali sync - 8 days ago 7
Vb.net Question

how do i update to number datatype by vb.net

when i use UPDATE query to update a value to NUMBER datatype field i get data type mismatch error

my code :

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 first parameter is NUMBER datatype in my access database

i try this for send parameters too :

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


also i try this :

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


also i try add :

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()


but same error

error msg :



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:





thanks for your answers

Answer

The error said

Message="Data type mismatch in criteria expression."

My Question is what is the datatype of your id_reg? is it a INT? if yes then do something like this.

change your

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

to

WHERE id_reg=" & Label58.Text

Comments