开发者

How to save byte[] to varbinary(64) field in database

I have

byte[] a = HashEncrypt("a");

with

public byte[] HashEncrypt(string password)
{
    SHA512Managed sha = new SHA512Managed();
    byte[] hash = sha.ComputeHash(UnicodeEncoding.Unicode.GetBytes(password));
    return hash;
}

I want to save byte[] a to my database. My database field is a varbinary(64). I'm u开发者_开发百科sing SQL Server 2008. I want to know the insert query with C# code.

I am using ADO.NET


Not quite sure how you're doing this as pointed out in the comments under your question, but I've added a byte[] to my db table by using a SqlParamenter inside of a SqlCommand.

SqlCommand cmd = new SqlCommand("insert into binaryTable (example) values (@example)",connection);
cmd.Parameters.Add(new SqlParameter("@example",HashEncript("password"));
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜