473,513 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String or binary data would be truncated

Coldfire
289 Contributor
i am having error ....details are

ASP.Net application...in which I have a textbox
<asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server" MaxLength="1000" /></asp:TextBox>

and this textbox is in a <asp:Repeater > which has the count of 35.

The textbox value is stored in the SQL DB
And the field data-type in the SQL DB is VARCHAR(1000)

Now the problem comes when I enter the text in the textbox with length more than 100(hundred) characters . The error that shows up is

----------------------
String or binary data would be truncated. The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated.

Stack Trace:

[SqlException: String or binary data would be truncated.
The statement has been terminated.]
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +195
XXXXXX.SqlHelper.ExecuteNonQuery(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
XXXXXX.SqlHelper.ExecuteNonQuery(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters)
XXXXXXL.SqlHelper.ExecuteNonQuery(String connectionString, String spName, Object[] parameterValues)
XXXXXX.Utilities.InsertCustomerService(Int32 MemberID, String OfferID, String CantAccess, String WontFunction, String Other)
----------------------

Now what i couldnt get is....the field length gives error when i give text more than 100 characters.......whats the deal with it..plz help asap!
Mar 5 '07 #1
7 17690
Coldfire
289 Contributor
in connection to my above query .......these are some more of the insights
regarding the error...i have found out that the main issue is in storedprocedure. But here in the SP , the length of the field is ntext rather than varchar(1000). But still it is not inserting values greater than 100 length

Msg 8152, Level 16, State 2, Procedure up_InsertCustomerService, Line 12
String or binary data would be truncated.
The statement has been terminated.
Mar 5 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Have you made changes to the design or stored procedure recently? Please post the stored procedure. Thanks.
Mar 6 '07 #3
Coldfire
289 Contributor
Have you made changes to the design or stored procedure recently? Please post the stored procedure. Thanks.
"up_InsertCustomerService" this is the stored procedure it has been using

[HTML]set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[up_InsertCustomerService]

@MemberID int,
@OfferID varchar(100),
@CantAccess varchar(100),
@WontFunction varchar(100),
@Other ntext

AS

INSERT INTO
CustomerService
(
MemberID,
OfferID,
CantAccess,
WontFunction,
Other
)
SELECT
@MemberID,
OfferIDList.Value,
CantAccessList.Value,
WontFunctionList.Value,
OtherList.Value
FROM
ufn_ConvertListToTable(@OfferID) OfferIDList
JOIN ufn_ConvertListToTable(@CantAccess) CantAccessList ON CantAccessList.ID = OfferIDList.ID
JOIN ufn_ConvertListToTable(@WontFunction) WontFunctionList ON WontFunctionList.ID = OfferIDList.ID
JOIN ufn_ConvertListToTable(@Other) OtherList ON OtherList.ID = OfferIDList.ID


[/HTML]
and the function "ufn_ConvertListToTable" is
[HTML]set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER FUNCTION [dbo].[ufn_ConvertListToTable] (@list ntext)
--set the Value varchar(100) to ntext
RETURNS @tbl TABLE (ID INT IDENTITY, Value ntext NOT NULL) AS
BEGIN
DECLARE
@pos int,
@textpos int,
@chunklen smallint,
@str nvarchar(4000),
@tmpstr nvarchar(4000),
@leftover nvarchar(4000)

SET @textpos = 1
SET @leftover = ''
WHILE @textpos <= datalength(@list) / 2
BEGIN
SET @chunklen = 4000 - datalength(@leftover) / 2
SET @tmpstr = ltrim(@leftover + substring(@list, @textpos, @chunklen))
SET @textpos = @textpos + @chunklen

SET @pos = charindex('|', @tmpstr)
WHILE @pos > 0
BEGIN
SET @str = substring(@tmpstr, 1, @pos - 1)
INSERT @tbl (Value) VALUES(@str)
SET @tmpstr = ltrim(substring(@tmpstr, @pos + 1, len(@tmpstr)))
SET @pos = charindex('|', @tmpstr)
END

SET @leftover = @tmpstr
END

IF ltrim(rtrim(@leftover)) <> ''
INSERT @tbl (Value) VALUES(@leftover)

RETURN
END




[/HTML]

I have found out the same reason of datatype mismatch or data-overflow but not yet pinpointed that at where in function "ConvertListToTable" it needs to be changed
Mar 6 '07 #4
Coldfire
289 Contributor
hurray ........... i have changed "@list ntext" to "@list varchar(1000)" and Value "varchar(100)" to "varchar(1000)" in the below given function that was called from my SP......Now its working fine ;)

[HTML]
ALTER FUNCTION [dbo].[ufn_ConvertListToTable] (@list ntext)
--set the Value varchar(100) to ntext
RETURNS @tbl TABLE (ID INT IDENTITY, Value ntext NOT NULL) AS
BEGIN
DECLARE
[/HTML]


regards
Saad
____________________________________________
Mar 6 '07 #5
kenobewan
4,871 Recognized Expert Specialist
Well done, thanks for sharing the solution :).
Mar 7 '07 #6
vainternet
1 New Member
or u could use ntext, it is bigger than varchar(1000)

here is a function for cutting the length of user data


Expand|Select|Wrap|Line Numbers
  1. public static string CutString(string text, int chars)
  2.     {
  3.         StringBuilder MyStringBuilder = new StringBuilder(text, chars);
  4.         if (MyStringBuilder.Length > chars)
  5.         {
  6.             MyStringBuilder.Length = chars;
  7.         }
  8.         return Common.deConverttoHtml(MyStringBuilder.ToString());
  9.     }
Jan 22 '08 #7
Baghul Mughal
1 New Member
Typically this error happens when there is a mismatch between data types. I have seen this error occur in many places including SSIS, Reporting Services and procs.

I would say use either CAST or CONVERT functions to make sure you are getting the correct data type and data length when passing the values.


Baghul
Instructor
Mar 24 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
39760
by: TZone | last post by:
Is there anything I can put in a stored procedure so instead of proc falling over because of "String or binary data would be truncated" the offending records are just truncated? Thanks for any...
3
40167
by: RDRaider | last post by:
How can I find which record(s) cause this error: Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. I have tried Profiler...
0
1248
by: benh | last post by:
Does anyone have any insight into how Application Center Test handles binary data in a response body? My problem: I need some specific data from inside a PDF file that is coming down as the...
1
2798
by: Bernie Yaeger | last post by:
What causes the error 'string or binary data would be truncated'? Here's the routine that sometimes causes the error, sometimes not: irow("ctotal") = FormatCurrency(irow("total"), 2,...
1
8050
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The...
0
1748
by: dileepkumar | last post by:
I'm trying to save file data to sqlserver. file data is converted to sysyte.io.stream and passed through webservice and in Business layer i changed the stream to byte array and passed it as a...
6
13307
by: dtarczynski | last post by:
Hello. I have problem when i inserting strings with special characters into MS SQL 2005 database for example:...
1
2367
by: dreamer247 | last post by:
hii My insert quary is giving an error "Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. " What may be the...
2
19305
by: sunkesula | last post by:
I update a field in the database that gives the last update time. The first time I edit the item it puts a value in this field. The second time the applications fails with The statement has...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.