andrewb andrewb - 2 years ago 66 Question

string or binary data would be truncated - do I need to specify size?

I am inserting data into a SQL Server database using VB.NET.

The column I am inserting into has a datatype of VARCHAR(MAX)

My SQL parameter is:

objPrm = New SqlParameter("@arg_strMessageText", SqlDbType.VarChar)

When I run the program I get the "String or binary data would be truncated" exception.

The size of the data I am trying to insert is 7,941 characters.

I thought the VARCHAR(MAX) datatype handled 8000 characters?

Answer Source

Well VarChar(MAX) can hold upto 2GB data. but you use Varchar(Max) you have to use -1 something like..

 objPrm = New SqlParameter("@arg_strMessageText", SqlDbType.VarChar, -1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download