3

I have a SqlDataSource and an <asp:ListView> setup to handle comments on another form, with the following textbox:

<asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' Width="400px" Height="125px" TextMode="MultiLine" /> 

The datasource has the following InsertCommand and asp:Parameter set on it:

InsertCommand="INSERT INTO [tblSLS_SpecComments] ([SpecID], [Author], [Comment]) VALUES (@SpecID, @Author, @Comment)" <asp:Parameter Name="SpecID" Type="Int32" /> <asp:Parameter Name="Author" Type="String" /> <asp:Parameter Name="Comment" Type="String" /> 

When I try to insert a longer comment (an example would be 500 'f's), I get an error:

String or binary data would be truncated.
The statement has been terminated.

The column that I'm inserting into is of datatype nvarchar(max), so it should be able to hold about a book's worth of characters, which is substantially fewer than I'm handing it.

Any clue about what's going on?

3
  • Can it be that you exceed the length of the Author column? Commented Jul 18, 2013 at 14:46
  • 1
    Shouldn't be. Author is setup as nvarchar(50), and is being truncated in code behind to only be the username (verified this). Commented Jul 18, 2013 at 14:48
  • @Crimius - Use SQL Server Profiler to trace the query being executed. You can then see exactly what is happening. I would think Mr Mush is correct here :) Commented Jul 19, 2013 at 13:47

4 Answers 4

1

You could check does your table have any trigger to another datatable, and the trigger tries insert/update the value into smaller field.

Sign up to request clarification or add additional context in comments.

Comments

0

Nvarchar(Max) can't be the source of that error. Check this question Check other field like Author and use MaxLenght property of texbox where ever possible.

Comments

0

It happened to me when I tried to insert long values from the designer (Edit top 200 rows...) on a nvarchar(max) field.

When I ran the update manually from the query window it worked.

Comments

0

I had a strange case with SQL Server 2008 where I could not insert into a nvarchar(max) column even if the query was not trying to insert anything at all (like Where 1 <> 1). The only solution that worked for me was sp_updatestats. Apparently, the server was thinking that the source column value could potentially be larger than nvarchar(max) (in fact it was nvarchar(20))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.