1. <tfoot id='OPo2P'></tfoot>
    2. <small id='OPo2P'></small><noframes id='OPo2P'>

    3. <legend id='OPo2P'><style id='OPo2P'><dir id='OPo2P'><q id='OPo2P'></q></dir></style></legend>
        <bdo id='OPo2P'></bdo><ul id='OPo2P'></ul>

      1. <i id='OPo2P'><tr id='OPo2P'><dt id='OPo2P'><q id='OPo2P'><span id='OPo2P'><b id='OPo2P'><form id='OPo2P'><ins id='OPo2P'></ins><ul id='OPo2P'></ul><sub id='OPo2P'></sub></form><legend id='OPo2P'></legend><bdo id='OPo2P'><pre id='OPo2P'><center id='OPo2P'></center></pre></bdo></b><th id='OPo2P'></th></span></q></dt></tr></i><div id='OPo2P'><tfoot id='OPo2P'></tfoot><dl id='OPo2P'><fieldset id='OPo2P'></fieldset></dl></div>

        如何将 Byte[] 插入 SQL Server VARBINARY 列

        时间:2023-08-19
        <tfoot id='zVOKN'></tfoot>

                <tbody id='zVOKN'></tbody>
              • <bdo id='zVOKN'></bdo><ul id='zVOKN'></ul>
                <legend id='zVOKN'><style id='zVOKN'><dir id='zVOKN'><q id='zVOKN'></q></dir></style></legend>

                <i id='zVOKN'><tr id='zVOKN'><dt id='zVOKN'><q id='zVOKN'><span id='zVOKN'><b id='zVOKN'><form id='zVOKN'><ins id='zVOKN'></ins><ul id='zVOKN'></ul><sub id='zVOKN'></sub></form><legend id='zVOKN'></legend><bdo id='zVOKN'><pre id='zVOKN'><center id='zVOKN'></center></pre></bdo></b><th id='zVOKN'></th></span></q></dt></tr></i><div id='zVOKN'><tfoot id='zVOKN'></tfoot><dl id='zVOKN'><fieldset id='zVOKN'></fieldset></dl></div>

                • <small id='zVOKN'></small><noframes id='zVOKN'>

                  本文介绍了如何将 Byte[] 插入 SQL Server VARBINARY 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在下面突出显示了一个字节数组,如何将其插入到 SQL Server 数据库的 Varbinary 列中?

                  I have a byte array highlighted below, how do I insert it into a SQL Server database Varbinary column?

                  byte[] arraytoinsert = new byte[10]{0,1,2,3,4,5,6,7,8,9};
                  
                  string sql = 
                      string.format
                      (
                      "INSERT INTO mssqltable (varbinarycolumn) VALUES ({0});",WHATTODOHERE
                      );
                  

                  推荐答案

                  我的解决方案是使用参数化查询,因为连接对象负责正确格式化数据(包括确保正确的数据类型,以及转义危险"字符(如适用):

                  My solution would be to use a parameterised query, as the connectivity objects take care of formatting the data correctly (including ensuring the correct data-type, and escaping "dangerous" characters where applicable):

                  // Assuming "conn" is an open SqlConnection
                  using(SqlCommand cmd = new SqlCommand("INSERT INTO mssqltable(varbinarycolumn) VALUES (@binaryValue)", conn))
                  {
                      // Replace 8000, below, with the correct size of the field
                      cmd.Parameters.Add("@binaryValue", SqlDbType.VarBinary, 8000).Value = arraytoinsert;
                      cmd.ExecuteNonQuery();
                  }
                  

                  添加了约翰桑德斯建议的包装使用"语句,以在完成后正确处理 SqlCommand

                  Added the wrapping "using" statement as suggested by John Saunders to correctly dispose of the SqlCommand after it is finished with

                  这篇关于如何将 Byte[] 插入 SQL Server VARBINARY 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:GroovySql:如何使用 Arraylist 变量更新表 下一篇:如何在 MySQL 中模拟数组变量?

                  相关文章

                  最新文章

                  <tfoot id='7WNbO'></tfoot>
                • <legend id='7WNbO'><style id='7WNbO'><dir id='7WNbO'><q id='7WNbO'></q></dir></style></legend>
                    <bdo id='7WNbO'></bdo><ul id='7WNbO'></ul>
                • <small id='7WNbO'></small><noframes id='7WNbO'>

                      <i id='7WNbO'><tr id='7WNbO'><dt id='7WNbO'><q id='7WNbO'><span id='7WNbO'><b id='7WNbO'><form id='7WNbO'><ins id='7WNbO'></ins><ul id='7WNbO'></ul><sub id='7WNbO'></sub></form><legend id='7WNbO'></legend><bdo id='7WNbO'><pre id='7WNbO'><center id='7WNbO'></center></pre></bdo></b><th id='7WNbO'></th></span></q></dt></tr></i><div id='7WNbO'><tfoot id='7WNbO'></tfoot><dl id='7WNbO'><fieldset id='7WNbO'></fieldset></dl></div>