If I have a field in MS SQL 2005 called "data" with type VarChar(MAX),
how do I add a parameter using the syntax below if SqlDbType doesn't
have a VarChar(MAX) type. If I use SqlDbType.VarChar will the value get
truncated or is that what I should use?

SqlCommand cmd = new SqlCommand(query, connection);
cmd.Parameters.Add("@data", SqlDbType.VarChar).Value = largeTextData;

Or am I supposed to use the size parameter?

cmd.Parameters.Add("@data", SqlDbType.VarChar, 1000000).Value =
largeTextData;

Also how many characters does VarChar(MAX) hold?

Re: SqlCommand Parameters with SqlDbType and VarChar(MAX) by Stephany

Stephany
Sun Jan 21 01:23:29 CST 2007

You do not need to supp ly a size at the time you add the paramater (for any
type). It is infered by the provider when the command is executed.

As many as you can throw at it up to a maximum of 2^31-1 bytes (not that is
bytes and NOT characters).



"Zeke Jones" <zekejones@gmail.com> wrote in message
news:1169363161.618300.154330@38g2000cwa.googlegroups.com...
> If I have a field in MS SQL 2005 called "data" with type VarChar(MAX),
> how do I add a parameter using the syntax below if SqlDbType doesn't
> have a VarChar(MAX) type. If I use SqlDbType.VarChar will the value get
> truncated or is that what I should use?
>
> SqlCommand cmd = new SqlCommand(query, connection);
> cmd.Parameters.Add("@data", SqlDbType.VarChar).Value = largeTextData;
>
> Or am I supposed to use the size parameter?
>
> cmd.Parameters.Add("@data", SqlDbType.VarChar, 1000000).Value =
> largeTextData;
>
> Also how many characters does VarChar(MAX) hold?
>