DataTable with a byte[] field as parameter to a stored procedure

后端 未结 1 1925
[愿得一人]
[愿得一人] 2021-01-05 05:16

I\'ve been reusing this method of using a DataTable as a parameter to a stored procedure and it\'s been working great. This is the simplified working code:



        
相关标签:
1条回答
  • 2021-01-05 05:54

    The representation for a binary string in .NET is the SqlBinary structure.

    You want to add your column like this:

    dt.Columns.Add("BinaryMessage", typeof(SqlBinary));
    

    The SqlBinary class has an explicit conversion to a byte array and an implicit conversion from a byte array, so the value from a byte array to the column is a simple matter of assignment, while getting a byte array from the column requires an explicit cast.

    0 讨论(0)
提交回复
热议问题