Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
usnig 👇 stored only 8000 char

What I have tried:

C#
SqlInputParam = new SqlParameter();
SqlInputParam = DBAccessHelper.SetParameter("@SiteText", SqlDbType.VarChar, 8000, ParameterDirection.Input, SiteNames);
SqlParams[34] = SqlInputParam;
Posted
Updated 30-Sep-20 21:37pm
v2

1 solution

You can try defining length at runtime or use -1.

C#
static void CreateSqlParameterSize()
{
    string description = "12 foot scarf - multiple colors, one previous owner";
    SqlParameter parameter = new SqlParameter("Description", SqlDbType.VarChar);
    parameter.Direction = ParameterDirection.InputOutput;
    parameter.Size = description.Length;
    parameter.Value = description;
}

Reference: SqlParameter.Size Property (System.Data.SqlClient) | Microsoft Docs[^]

Quote:
if the NVARCHAR parameter has MAX data length, Simply set it as -1. -1 is the magic number for this data length.

Ex:
C#
SqlParameter param = new SqlParameter("@value", SqlDbType.NVarChar, -1);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900