有个问题,我把代码发给大家看,请教一下
private void button2_Click(object sender, System.EventArgs e)
{
FileStream fs;
string PathImage;
OleDbConnection OleConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=anhua.mdb");
OleConn.Open();
if (DialogResult.OK == this.openFileDialog1.ShowDialog())
{
PathImage=this.openFileDialog1.FileName;
fs=new FileStream(PathImage,System.IO.FileMode.Open ,System.IO.FileAccess.Read );
byte[] ib=new byte[fs.Length];
fs.Read(ib,0,ib.Length);
fs.Close();
OleDbCommand cmd = new OleDbCommand("INSERT INTO [Image1](Image1) VALUES (@img )" ,OleConn);
((OleDbParameter)cmd.Parameters.Add( "@img" , OleDbType.Binary )).Value = ib;
cmd.ExecuteNonQuery();
OleConn.Close();
cmd.Dispose();
MessageBox.Show("图片写入成功!");
}
}
我第一次载入的时候没问题,第2次载入就在if (DialogResult.OK == this.openFileDialog1.ShowDialog())这出错了,很郁闷啊!
问题点数:10、回复次数:2Top
1 楼bbdog(贝贝狗)回复于 2006-12-03 13:49:20 得分 0
关注Top
2 楼wshxzx(雕刻时光)回复于 2007-02-24 11:48:03 得分 10
this.openFileDialog1对象没有关闭
Top




