10

I keep getting this error

ErrorSystem.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at workOrder.btnSubmit_Click(Object sender, EventArgs e) in h:\WebSite1\workOrder.aspx.cs:line 60 ClientConnectionId:2b010913-ba9f-4423-b6e1-2e9a038431ce

and googling tells me that a string input is too long to be processed by the database, but all of my fields are large enough and i cant figure this out,

here is my code:

  <!--Removed-->

I get this error even when I leave every nullable field blank and only input 1 character for the rest of the items

Edit: The Table:

<!--Removed-->

Edit:

asp code:

<!--Removed-->

Edit: Removed all code for security,

Andrew Diamond
  • 6,295
  • 1
  • 15
  • 33
  • Maybe you are passing unicode strings to non unicode table fields? – e4rthdog May 10 '14 at 15:00
  • SHow the sql table schema (columns and column type definitions), and replace query with string literals you are trying to insert (the values inside the `Values()` parentheses in the Insert statement). – Charles Bretana May 10 '14 at 15:04
  • I'm importing this into NCHAR data Type fields, would that cause an issue? – Andrew Diamond May 10 '14 at 15:07
  • Have you tried the insert query in sql server management studio with an actual execution plan? Had the same thing caused by a trigger once. – Me.Name May 10 '14 at 15:13
  • @charles-bretana Edited the post to show the table – Andrew Diamond May 10 '14 at 15:16
  • @Me.Name unfortunately I only have the SQL Server built into Visual Studio, so I dont know how I would do that – Andrew Diamond May 10 '14 at 15:17
  • Now edit the insert statement to pass actual literal values instead of input parameter values, and see if the error persists... – Charles Bretana May 10 '14 at 15:19
  • like this: `com.Parameters.AddWithValue("@nameFirst", "Robert");` etc. – Charles Bretana May 10 '14 at 15:20
  • Don't know if visual studio supports anything like an execution plan these days, but the server explorer should be able to show if any triggers are attached to the table (underneath the fields listing) – Me.Name May 10 '14 at 15:24
  • @Charles ok so I did what you said and still got the same error. So the issue is with my table? – Andrew Diamond May 10 '14 at 15:31
  • Have you tried explicitly setting the parameter types when initializing the command parameters? – Martin Costello May 10 '14 at 15:33
  • @martin_costello like this? com.Parameters.AddWithValue("@nameFirst", "Robert"); com.Parameters.AddWithValue("@nameLast", "Man"); com.Parameters.AddWithValue("@phoneNumber", "5555555555"); com.Parameters.AddWithValue("@callWhenReady", "yes"); com.Parameters.AddWithValue("@email", "email@example.com"); com.Parameters.AddWithValue("@addressStreet", "3333 SomeStreet"); com.Parameters.AddWithValue("@addressCity", "City"); com.Parameters.AddWithValue("@addressZip", "44444");.... – Andrew Diamond May 10 '14 at 15:45
  • txtMake.ToString() length is 37 , if you are using below code * – Kumar Manish May 10 '14 at 15:48

1 Answers1

14

This is error occurs when your column size is less than your text size.

For Example : In Database you have column " name varchar(10)" and the size of your data is greater than 10 . At this Situation error is occurred.

EX : If i enter "Siddharth Shukla" in name field than it will give error . so i have to change my column size from 10 to 20.

siddharth
  • 256
  • 4
  • 14