请问如何将图片更新到sql的image字段中?
请问在vb.net下,如何使用update 来更新一个图片到到sql的image字段中?
可以给个例子吗?
[解决办法]
两种办法,一种是数据流,图片保存为二进制字节。
HttpPostedFile hpf = this.FileUpload1.PostedFile; int intlenght = hpf.ContentLength; byte[] arrBt = new byte[intlenght]; Stream strm = hpf.InputStream; strm.Read(arrBt, 0, intlenght); con.ConnectionString = ConfigurationManager.ConnectionStrings["sqlStr"].ConnectionString; con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "insert imgfile values(@imgfile,@imgsize)"; cmd.Parameters.AddWithValue("@imgfile", arrBt); cmd.Parameters.AddWithValue("@imgsize", intlenght); cmd.ExecuteNonQuery();