还是使用Command对象,用存储过程单独更新大对象列吧。

解决方案 »

  1.   

    数据库里面这个字段的数据类型是是什么啊?如果是SQLServer的话,应该用Image类型
      

  2.   

    1. 你用这样的方法的话,要存储的文件不能太大的, 太大的话,你想一想你要一下全读取内存里,怎么可行.
    2 .出错提示:将截断二进制或字符串  你的数据表中该列是什么类型的,?如果超出8000字节,要用varbinary(max)的.
    3. 文件大的话,要用分段保存,即一次保存一小段如8K到数据库中,读一段写入一段.网上有很多这样的例子.
      

  3.   

    截断是大小问题
    FileStream fs = new FileStream(@"D:\a.jpg", FileMode.Open,FileAccess.Read);
                Byte[] btye2 = new byte[fs.Length];
                fs.Read(btye2 , 0, Convert.ToInt32(fs.Length));
                fs.Close();
                using (SqlConnection conn = new SqlConnection(sqlconnstr))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = "insert into Photo(imgfile) values(@imgfile)";
                    SqlParameter par = new SqlParameter("@imgfile", SqlDbType.Image);
                    par.Value = bt;
                    cmd.Parameters.Add(par);
                    int t=(int)(cmd.ExecuteNonQuery());
                    conn.Close();
                 }  SqlConnection conn=new SqlConnection() 
         conn.ConnectionString="Data Source=localhost;Database=test;User Id=sa;Pwd=sa";      
                    string strSql="";
                    SqlCommand cmd=new SqlCommand() 
                    reader.Read(); 
                    Response.ContentType="application/octet-stream"; 
                    Response.BinaryWrite((Byte[])reader["FImage"]); 
                    Response.End(); 
                    reader.Close(); 
      

  4.   

    通过存储过程更新数据库中图片,图片太大消耗内存。
    要先清空那个原有的image,再插入