三层里面把image按byte[]处理了,这样传到数据库的是byte[],赋值就会报错。所以需要重写底层,用
SqlDbType.Image类型传值。
public bool update_img(Entity.TB_SigNet model) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); string strCom = "update TB_SigNet set Context= @Context where id='" + model.Id + "'"; SqlCommand com = new SqlCommand(strCom, conn); com.Parameters.Add("@Context", SqlDbType.Image).Value = model.Context; com.ExecuteNonQuery(); return true; }
上面代码其实没有生成的三层,直接用sql语句写了。