请大侠指教,我如何用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.   

    用参数化sql语句。
    把tel给一个参数赋值即可。http://www.cnblogs.com/cancer_xu/archive/2009/09/13/1565845.html
      

  2.   

     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();
                }我这样写对吗
      

  3.   


    --创建表 
    create   table   test(col  varbinary(4000)) 
    go --创建存储过程 
    create   procedure   sp_savaBinary(@binary   varbinary(4000)) 
    as 
            insert   into   test   values(@binary) 
    go --调用存储过程插入数据 
    declare   @binary   varbinary(4000) 
    set   @binary   =   cast( '12sfasfasfasf '   as   varbinary(4000)) 
    exec   sp_savaBinary   @binary 
      

  4.   

    注意相应字段可以用image类型http://www.cnblogs.com/adamoooo/articles/788913.html
      

  5.   


       //将流转换成数组
       byte[] bWrite = mstream.ToArray();
       //将数组写入数据库
       System.Data.SqlClient.SqlParameter[] pram ={
              sqlHelper.MakeInParam("@XX",System.Data.SqlDbType.Image)
       };
       pram[0].Value = bWrite;
       //执行SQL
       //xxxxxxxxxx("insert into XXX (XX) values (@XX)", pram);
      

  6.   

    我这数据格式该怎么转换,总是说我转换无效  public static void updateState(long id, byte[] tel)
            {            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", SqlDbType.Image);
                    mycom.Parameters["@tel"] = tel;
                    mycom.Parameters.Add("@id", SqlDbType.BigInt);
                    mycom.Parameters["@id"] =id;
                    mycom.ExecuteNonQuery();
                }
                catch (Exception exe)
                {
                    Console.Write(exe.Message);
                }
            }
      

  7.   

    SQL Server中的Image数据类型的操作,看下这个吧,应该能帮你解决的!