Yus*_*tme 45 c# sql-server bytearray
如何将byte []数组保存到SQL Server数据库中?此byte []包含HashAlgorithm值.
需要再次使用该数据以供以后使用.因此,转换它而不是将其恢复到原始状态,这不是我想要的.
提前致谢!
mar*_*c_s 68
你应该能够写出这样的东西:
string queryStmt = "INSERT INTO dbo.YourTable(Content) VALUES(@Content)";
using(SqlConnection _con = new SqlConnection(--your-connection-string-here--))
using(SqlCommand _cmd = new SqlCommand(queryStmt, _con))
{
SqlParameter param = _cmd.Parameters.Add("@Content", SqlDbType.VarBinary);
param.Value = YourByteArrayVariableHere;
_con.Open();
_cmd.ExecuteNonQuery();
_con.Close();
}
Run Code Online (Sandbox Code Playgroud)
使用Linq-to-SQL,你会写这样的东西:
using(YourDataContextHere ctx = new YourDataContextHere())
{
SomeClassOfYours item = new SomeClassOfYours();
item.ByteContent = (your byte content here);
ctx.SomeClassOfYourses.InsertOnSubmit(item);
ctx.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)
这会将您的SQL Server表中的类型byte[]列作为字节流插入,您可以稍后再读回1:1.ContentVARBINARY