SqlCommand Parameters with SqlDbType and VarChar(MAX)

Z

Zeke Jones

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?
 
S

Stephany Young

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top