Access内保存图像Test

类别:编程语言 点击:0 评论:0 推荐:
private void button1_Click(object sender, System.EventArgs e)
{
OleDbConnection mycnn=new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=f:\\dazhu.mdb");
mycnn.Open();

OleDbCommand mycmd=new OleDbCommand("update info set picture=@a",mycnn );

FileStream mystream=new FileStream("f:\\1.jpg",FileMode.Open,FileAccess.Read);
long len=mystream.Length;

mycmd.Parameters.Add("@a",OleDbType.Binary,(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();
}

本文地址:http://com.8s8s.com/it/it24495.htm