Click here to Skip to main content
13,868,937 members
Rate this:
Please Sign up or sign in to vote.
My query on button click is this
Dim ms As New MemoryStream()
       PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
       Dim data As Byte() = ms.GetBuffer()

       sql = "insert into emp_det values(?,?,?,?,?,?,?,?,?,?)"
       cmd = New SqlCeCommand(sql, con)
       cmd.Parameters.Add("@eid", SqlDbType.Float).Value = 10001
       cmd.Parameters.Add("@emp_id", SqlDbType.NVarChar).Value = "A123"
       cmd.Parameters.Add("@ename", SqlDbType.NVarChar).Value = "Kashif Alvi"
       cmd.Parameters.Add("@eadd", SqlDbType.NVarChar).Value = "A 502 Trivedi Plaza Hydri Chowk Naya Nagar Mira Road East"
       cmd.Parameters.Add("@mobile_no", SqlDbType.Float).Value = 9773582894
       cmd.Parameters.Add("@email_id", SqlDbType.NVarChar).Value = ""
       cmd.Parameters.Add("@bg", SqlDbType.NVarChar).Value = "A +ve"
       cmd.Parameters.Add("@photo", SqlDbType.Image).Value = data
       cmd.Parameters.Add("@dob", SqlDbType.DateTime).Value = DateTimePicker1.Value
       cmd.Parameters.Add("@doj", SqlDbType.DateTime).Value = Date.Now
       retval = cmd.ExecuteNonQuery
   End Sub

And i am getting an error

The data was truncated while converting from one data type to another. [ Name of function(if known) = ]

Detailed error below

System.Data.SqlServerCe.SqlCeException was unhandled
Message="The data was truncated while converting from one data type to another. [ Name of function(if known) = ]"
Source="SQL Server Compact ADO.NET Data Provider"
at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr) at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor) at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery() at Payroll.Form1.Button2_Click(Object sender, EventArgs e) in D:\Kashif\GIV\Payroll\Payroll\Form1.vb:line 64 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 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) 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 Payroll.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()

What should i do now
Hasham Ahmad 2-Jul-13 7:17am
you need to check the datatypes of all the fields from the table emp_det and match them in your code .... or you can just share the table structure of emp_det
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Name the parameters!
sql = "insert into emp_det values(@eid, @emp_id, @ename,...

But by preference, name your fields as well:
sql = "INSERT INTO emp_det (Eid, emp_id, ename, ...) VALUES (@eid, @emp_id, @ename,...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Map all the datatypes and must match range of datatype...i think you gave small range for any datatype there for data has been truncate.....:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190214.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100