从SQL Server到C#阅读VARBINARY(MAX) [英] Read VARBINARY(MAX) from SQL Server to C#

查看:237
本文介绍了从SQL Server到C#阅读VARBINARY(MAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从SQL Server 2008中的一列的类型为 VARBINARY(MAX)读取数据行。在C#我想用out参数读取它(定方案满足需求居多)。

但我需要指定的参数变量的大小,填补了C#的变量。 在这里,我认为8000就足够了...但谁知道:

  database.AddOutParameter(命令,vbCertificate,DbType.Binary,8000);
 

所以,问题是:

  1. 什么是最大的数目为SQL Server 2008?
  2. 的大小
  3. 这是确定使用out参数对于这种情况?
解决方案

由于@marc_s说,我只是想补充一下。

有两种数据类型

[(N)]

固定长度的二进制数据,其长度为n字节,其中n是从1至8000的值。存储大小为n个字节。

VARBINARY [(N | MAX)]

可变长度的二进制数据。 n可以是从1到8000的值。 max指示最大存储尺寸是2 ^ 31-1(等于int.MaxValue即2,147,483,647)字节。存储大小是根据输入+2字节的数据的实际长度。所输入的数据可以是在长度0字节。

如果您指定的最大那么你关注的应该是与VARBINARY而非二进制

database.AddOutParameter(命令,vbCertificate,DbType.Binary,8000);

database.AddOutParameter(命令,vbCertificate,SqlDbType.VarBinary,int.MaxValue);

I need to read data row from SQL Server 2008. The type of one of the columns is VARBINARY(MAX). In C# I want to use out parameter to read it (and given scenario satisfies the needs mostly).

But I need to specify the parameter variable size to fill the C# variable. Here I assume that 8000 is enough... But who knows:

database.AddOutParameter(command, "vbCertificate", DbType.Binary, 8000);

So the questions are:

  1. What is the size of MAX in number for SQL Server 2008?
  2. Is this ok to use out parameter for this scenario?

解决方案

As @marc_s said, I will just want to add something.

There are two data types

binary [ ( n ) ]

Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.

varbinary [ ( n | max) ]

Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 (equals int.MaxValue i.e. 2,147,483,647) bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length.

if you are specifying max then your concern should be with varbinary instead of binary

database.AddOutParameter(command, "vbCertificate", DbType.Binary, 8000);

database.AddOutParameter(command, "vbCertificate", SqlDbType.VarBinary, int.MaxValue);

这篇关于从SQL Server到C#阅读VARBINARY(MAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆