C# 您在参数声明中使用的 varchar(MAX) 大小是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/973260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What size do you use for varchar(MAX) in your parameter declaration?
提问by mrblah
I normally set my column size when creating a parameter in ADO.NET
我通常在 ADO.NET 中创建参数时设置我的列大小
But what size do I use if the column is VARCHAR(MAX)
?
但是,如果列是 ,我使用什么尺寸VARCHAR(MAX)
?
cmd.Parameters.Add("@blah", SqlDbType.VarChar, ?????).Value = blah;
采纳答案by Micha? Chaniewski
In this case you use -1.
在这种情况下,您使用 -1。
回答by Sam Meshesha
For those of us who did not see -1 by Michal Chaniewski, the complete line of code:
对于我们这些没有看到 Michal Chaniewski 的 -1 的人,完整的代码行:
cmd.Parameters.Add("@blah",SqlDbType.VarChar,-1).Value = "some large text";
回答by Eric Draven
The maximum SqlDbType.VarChar size is 2147483647.
SqlDbType.VarChar 的最大大小为 2147483647。
If you would use a generic oledb connectioninstead of sql, I found herethere is also a LongVarChar datatype. Its max size is 2147483647.
如果您将使用通用oledb 连接而不是 sql,我发现这里还有一个 LongVarChar 数据类型。其最大大小为 2147483647。
cmd.Parameters.Add("@blah", OleDbType.LongVarChar, -1).Value = "very big string";
回答by Igor Macedo
You do not need to pass the size parameter, just declare Varchar
already understands that it is MAX like:
你不需要传递 size 参数,只要声明Varchar
已经明白它是 MAX 就像:
cmd.Parameters.Add("@blah",SqlDbType.VarChar).Value = "some large text";
回答by Alberto Tromba
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.
当它是一个输出参数时,这可能会出现问题,您不会再返回任何字符,然后将其作为输入。