请大侠指教,我如何用sql写,将二进制数组存入字段类型为Image的字段中,sqlserver2008环境
 public static void updateState(long id, byte[] tel)
        {
            string strUpdate = "update T_Res set Tel=" +tel + ",Hobbies=5 where ID=" + id;

解决方案 »

  1.   

    最好用存储过程来解决.在调用存储过程时,你可以直接设置 parameter 的数据类型.
      

  2.   

    IMAGE字段还是建议存储图片的路径 程序中调用路径
      

  3.   

    先将二进制数组转为二进制字符串,然后insert into [表名]([image字段]) select cast([二进制字符串] as binary)
      

  4.   

     string strUpdate = string.Format("update T_Resume set Tel=@tel,Hobbies=5 where ID=@id");
                try
                {
                    SqlParameter sp = new SqlParameter("@tel",tel,SqlDbType.Image);
                    SqlParameter sp1 = new SqlParameter("@id", tel, SqlDbType.BigInt);
                    mycon = GetCon();
                    mycon.Open();
                    mycom = new SqlCommand(strUpdate, mycon);
                   
                    mycom.ExecuteNonQuery();
                }我这样写对吗,
      

  5.   

                string strUpdate = string.Format("update T_Resume set Tel=@tel,Hobbies=5 where ID=@id");
                try
                {
                    mycon = GetCon();
                    mycon.Open();
                    mycom = new SqlCommand(strUpdate, mycon);
                    mycom.Parameters.Add("@tel", tel, SqlDbType.Image);
                    mycom.Parameters.Add("@id", tel, SqlDbType.BigInt);
                    mycom.ExecuteNonQuery();
                }
      

  6.   

    如何把Long类型转换成 BigInt
              try
                {
                    mycon = GetCon();
                    mycon.Open();
                    mycom = new SqlCommand(strUpdate, mycon);
                    mycom.Parameters.Add("@tel", SqlDbType.Image);
                    mycom.Parameters["@tel"] = tel;
                    mycom.Parameters.Add("@id", SqlDbType.BigInt);
                    mycom.Parameters["@id"] = id;??????id为long
                    mycom.ExecuteNonQuery();
                }