保存图片到数据库
private SqlConnection mycnn=null;
//保存图片到数据库
mycnn=new SqlConnection(@"server=zhurongj;database=my1;Trusted_connection=yes");
mycnn.Open();
SqlCommand mycmd=new SqlCommand("update picture set picture=@a where ID=1",mycnn);
FileStream mystream=new FileStream("f://1.jpg",FileMode.Open,FileAccess.Read);
long len=mystream.Length;
mycmd.Parameters.Add("@a",SqlDbType.Image,(int)len,"picture");
mycmd.Parameters["@a"].Direction=System.Data.ParameterDirection.Input;
byte []box=new byte[len];
mystream.Read(box,0,(int)len);
mycmd.Parameters["@a"].Value=box;
//更新
mycmd.ExecuteNonQuery();
MessageBox.Show("ok");
mystream.Close();
mycnn.Close();