更新时间:2023-02-07 09:36:16
您应该可以编写如下内容:
You should be able to write something like this:
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();
}
使用Linq-to-SQL,您将编写如下内容:
Using Linq-to-SQL, you'd write something like this:
using(YourDataContextHere ctx = new YourDataContextHere())
{
SomeClassOfYours item = new SomeClassOfYours();
item.ByteContent = (your byte content here);
ctx.SomeClassOfYourses.InsertOnSubmit(item);
ctx.SubmitChanges();
}
这会将您的byte[]
作为字节流插入到SQL Server表中类型为VARBINARY
的列Content
的列Content
中,稍后您可以再次读取1:1.
That will insert your byte[]
into a column Content
of type VARBINARY
in your SQL Server table as a byte stream, which you can read back 1:1 again later on.