Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-CE SQL
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 = "kashif.alvi39@hotmail.com"
        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
        MsgBox(retval)
    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
HResult=-2147467259
Message="The data was truncated while converting from one data type to another. [ Name of function(if known) = ]"
NativeError=25920
Source="SQL Server Compact ADO.NET Data Provider"
StackTrace:
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()
InnerException:
 

 
What should i do now
Posted 2-Jul-13 2:12am
Comments
Hasham Ahmad at 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
good
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,...
  Permalink  
Rate this: bad
good
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.....Smile | :)
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 334
1 Kornfeld Eliyahu Peter 325
2 Maciej Los 239
3 OriginalGriff 188
4 King Fisher 185
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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