Read VARBINARY(MAX) from SQL Server to C#(从 SQL Server 读取 VARBINARY(MAX) 到 C#)
问题描述
我需要从 SQL Server 2008 读取数据行.其中一列的类型是 VARBINARY(MAX)
.在 C# 中我想使用 out 参数来读取它(并且给定的场景主要满足需求).
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).
但是我需要指定参数变量大小来填充C#变量.这里我假设8000就够了……但谁知道呢:
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);
所以问题是:
- SQL Server 2008 的最大数量是多少?
- 在这种情况下可以使用 out 参数吗?
推荐答案
正如@marc_s 所说,我只想添加一些东西.
As @marc_s said, I will just want to add something.
有两种数据类型
二进制 [ ( n ) ]
长度为 n 字节的定长二进制数据,其中 n 是从 1 到 8,000 的值.存储大小为 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) ]
varbinary [ ( n | max) ]
可变长度二进制数据.n 可以是 1 到 8,000 之间的值.max 表示最大存储大小为 2^31-1(等于 int.MaxValue 即 2,147,483,647)字节.存储大小是输入数据的实际长度 + 2 个字节.输入的数据长度可以是0字节.
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.
如果您指定 max,那么您应该关注 varbinary 而不是 binary
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);
database.AddOutParameter(command, "vbCertificate", SqlDbType.VarBinary, int.MaxValue);
这篇关于从 SQL Server 读取 VARBINARY(MAX) 到 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 SQL Server 读取 VARBINARY(MAX) 到 C#


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01