从 SQL Server 读取 VARBINARY(MAX) 到 C#

编程入门 行业动态 更新时间:2024-10-11 13:19:47
本文介绍了从 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#

    本文发布于:2023-11-08 06:14:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1568565.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Server   SQL   MAX   VARBINARY

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!