想把图片保存在数据库中,用的是access,不知道为什么一运行出以下错误
“未处理的System.IndexOutOfRangeException类型的异常出现在system.data.dll中
在位置7出没有任何行”
第7行就是以下我标注的那行,谢谢大家的帮助。
private void btnPicture_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetEmployy,"Employee"].Position;
this.openFileDialog1.InitialDirectory="c:\\Picture";
this.openFileDialog1.Filter="jpg files(*.jpg)|*.jpg|gif files(*.gif)|*.gif|bmp files(*.bmp)|*.bmp|All files (*.*)|*.*";
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.pictureBox1.Image=Image.FromFile(this.openFileDialog1.FileName);
第七行 this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"]=this.openFileDialog1.FileName;
}
}
private void Picture_Change(int position)
{
if(this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"].ToString()!="") {
this.pictureBox1.Image=Image.FromFile(this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"].ToString()); }
else
return;
}
“未处理的System.IndexOutOfRangeException类型的异常出现在system.data.dll中
在位置7出没有任何行”
第7行就是以下我标注的那行,谢谢大家的帮助。
private void btnPicture_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetEmployy,"Employee"].Position;
this.openFileDialog1.InitialDirectory="c:\\Picture";
this.openFileDialog1.Filter="jpg files(*.jpg)|*.jpg|gif files(*.gif)|*.gif|bmp files(*.bmp)|*.bmp|All files (*.*)|*.*";
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.pictureBox1.Image=Image.FromFile(this.openFileDialog1.FileName);
第七行 this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"]=this.openFileDialog1.FileName;
}
}
private void Picture_Change(int position)
{
if(this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"].ToString()!="") {
this.pictureBox1.Image=Image.FromFile(this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"].ToString()); }
else
return;
}
你的this.DataSetEmployy.Tables["Employee"].Rows.Count是多少啊?
“未处理的System.IndexOutOfRangeException类型的异常出现在system.data.dll中
在位置7出没有任何行”
第7行就是以下我标注的那行,谢谢大家的帮助。
第七行 this.DataSetEmployy.Tables["Employee"].Rows[position]["Picture"]=this.openFileDialog1.FileName;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~提示信息不是这个意思,说的你是的datatable没有第七条记录把你的这个错误信息的跟踪信息贴出来看看