请教各位高手,如何往数据库中添加一个byte数组
以前没有用过C#,最近刚开始接触。现在需要把一个20位的byte数组插入到数据库中(作为ID,是表的主键),我根据网上的资料写出了相关的实现程序,其他字段都插入成功了,但是数据库中的ID字段显示为“<Binary data>”,ID的数据类型是binary(20)。
以下为源代码:
--------------------编程问答-------------------- 补充一下,数据库采用的是SQL Server2005
SqlConnection oConn = new SqlConnection(ProjectConfigure.DBConnString); //ProjectConfigure.DBConnString可以从配置文件中读出
SqlCommand oCommand = new SqlCommand("Add", oConn);
oCommand.CommandType = CommandType.StoredProcedure;
byte[] tmp = new byte[] {25,16,42,125,103,
25,16,42,125,103,
25,16,42,125,103,
25,16,42,125,103};
string tmp2 = “test”;
oCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarBinary, 20));
oCommand.Parameters["@ID"].Value = tmp;
oCommand.Parameters.AddWithValue("@Name", Name);
oCommand.ExecuteNonQuery();
补充:.NET技术 , ASP.NET