i used SqlDbtype.NVarchar as below to allow normal text string to be input to the textbox and save. On the other hand, i defined the data type as Nvarchar(MAX) and below i notice the SIZE specified -1,
SqlCommand cmdSQL =
new
SqlCommand(strSQL, objConn);
cmdSQL.Parameters.Add(
new
SqlParameter("@strDescription",
SqlDbType.NVarChar, 1000));
cmdSQL.Parameters[
"@strDescription"].Value = strDesc;
I found out If i replace NVarchar with Varchar(MAX), and i will successfully edited if the line does not exist more than 1 line in the textbox,
So if the size of column “strDescription” is less than 1000, we will get the error. What’s the data type of column “strDescription”? I think we can fix the issue by changing it to NVARCHAR(MAX).
Might be worth pointing out here, given it turned up when I was trying to solve this issue, if you are using a function you wrote, check what it returns.
I had a date, which could never be more than 10 characters, returning 50 chars. This slightly disguised the problem - hope this helps someone.
csharp_start...
Member
15 Points
182 Posts
String or binary data would be truncated. The statement has been terminated.
Mar 20, 2009 07:46 AM|LINK
i used SqlDbtype.NVarchar as below to allow normal text string to be input to the textbox and save. On the other hand, i defined the data type as Nvarchar(MAX) and below i notice the SIZE specified -1,
SqlCommand cmdSQL = new SqlCommand(strSQL, objConn);cmdSQL.Parameters.Add(
new SqlParameter("@strDescription", SqlDbType.NVarChar, 1000));cmdSQL.Parameters[
"@strDescription"].Value = strDesc;I found out If i replace NVarchar with Varchar(MAX), and i will successfully edited if the line does not exist more than 1 line in the textbox,
TextMode
="MultiLine" Height="250" Columns="50"qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: String or binary data would be truncated. The statement has been terminated.
Mar 20, 2009 09:20 AM|LINK
Hi,
Kindly Check in table..what Length Have u kept for that Filed..
Hope it helps
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
l0n3i200n
Participant
1443 Points
337 Posts
Re: String or binary data would be truncated. The statement has been terminated.
Mar 20, 2009 09:37 AM|LINK
Check the size allowed in the Database column in SQL. Varchar(max) if I can remember correctly allows 8000 chars.
csharp_start...
Member
15 Points
182 Posts
Re: String or binary data would be truncated. The statement has been terminated.
Mar 20, 2009 10:04 AM|LINK
i read the article on the link below, it enables maxlength in textbox once multilined with js, but still the text got truncated after next line
http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=limitMultiText
<
script language="javascript" type="text/javascript"> function textCounter(field, countfield, maxlimit) {if (field.value.length > maxlimit) {field.value = field.value.substring(0, maxlimit);
} else {countfield.value = maxlimit - field.value.length;
}
}
</
script> <asp:TextBox onkeydown="textCounter(this.form.txtmessage,this.form.txtLen,1000)" onkeyup="textCounter(this.form.txtmessage,this.form.txtLen,1000)" runat="Server" ID="txtDesc" TextMode="MultiLine" Height="250" Columns="50" Text='<%#DataBinder.Eval(Container.DataItem, "BahasaMalaysia").ToString()%>' /> <asp:TextBox BackColor="Blue" BorderStyle="None" Width="30" ForeColor="White" Font-Bold="True" id="txtLen" Runat="server" Text="100" />Jian Kang - ...
All-Star
33132 Points
2465 Posts
Re: String or binary data would be truncated. The statement has been terminated.
Mar 25, 2009 09:35 AM|LINK
Hi,
This issue is caused by we are trying to insert values in a column greater than the max size of the column specified.
I notice that the parameter’s length is 1000:
cmdSQL.Parameters.Add(new SqlParameter("@strDescription", SqlDbType.NVarChar, 1000));So if the size of column “strDescription” is less than 1000, we will get the error. What’s the data type of column “strDescription”? I think we can fix the issue by changing it to NVARCHAR(MAX).Related document:
nchar and nvarchar (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms186939.aspx
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Grady Christ...
Member
96 Points
22 Posts
Re: String or binary data would be truncated. The statement has been terminated.
Mar 25, 2009 01:20 PM|LINK
If you're certain that your data will remain intact you can insert this t-sql statement before you execute your query:
set
ansi_warnings offHope it helps. Thanks, Grady Christie
PancakeGeels
Member
10 Points
19 Posts
Re: String or binary data would be truncated. The statement has been terminated.
May 21, 2010 01:28 PM|LINK
Might be worth pointing out here, given it turned up when I was trying to solve this issue, if you are using a function you wrote, check what it returns.
I had a date, which could never be more than 10 characters, returning 50 chars. This slightly disguised the problem - hope this helps someone.