Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 435 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What size do you use for varchar(MAX) in your parameter declaration?

#1
I normally set my column size when creating a parameter in ADO.NET.

But what size do I use if the column is of type `VARCHAR(MAX)`?

cmd.Parameters.Add("@blah", SqlDbType.VarChar, ?????).Value = blah;
Reply

#2
In this case you use -1.
Reply

#3
For those of us who did not see -1 by Michal Chaniewski, the complete line of code:

cmd.Parameters.Add("@blah",SqlDbType.VarChar,-1).Value = "some large text";
Reply

#4
The maximum SqlDbType.VarChar size is 2147483647.

If you would use a generic **oledb connection** instead of sql, I found [here][1] there is also a LongVarChar datatype. Its max size is 2147483647.

cmd.Parameters.Add("@blah", OleDbType.LongVarChar, -1).Value = "very big string";



[1]:

[To see links please register here]

Reply

#5
You do not need to pass the size parameter, just declare `Varchar` already understands that it is MAX like:

cmd.Parameters.Add("@blah",SqlDbType.VarChar).Value = "some large text";
Reply

#6
If you do something like this:


cmd.Parameters.Add("@blah",SqlDbType.VarChar).Value = "some large text";

size will be taken from "some large text".Length

This can be problematic when it's an output parameter, you get back no more characters then you put as input.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through