Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My query on button click is this
VB
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
Comments
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

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.....:)
 
Share this answer
 
v2
Name the parameters!
C#
sql = "insert into emp_det values(@eid, @emp_id, @ename,...

But by preference, name your fields as well:
C#
sql = "INSERT INTO emp_det (Eid, emp_id, ename, ...) VALUES (@eid, @emp_id, @ename,...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900