在datagrid中删除选中行是出现异常。
private void delete_Click(object sender, System.EventArgs e)
{
//
int num=ds.Tables["个人其他信息"].Rows.Count-1;
if(num>-1)
{
ArrayList ar=new ArrayList();
for(int i=num;i>=0;i--)
{
if(this.dataGrid1.IsSelected(i))
{
ar.Add(i);
}
}
if(ar.Count>0)
{
if(MessageBox.Show("确实要删除选中的"+ar.Count.ToString()+
"行吗? 注意:删除后就无法恢复了!","警告",
MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
foreach(int i in ar)
{
ds.Tables["个人基本信息"].Rows[i].Delete();
}
da.Update(ds,"个人其他信息");
}
}
else
{
MessageBox.Show("请先用鼠标点击左边灰色部分选择要删除的"+
"行(可以按住Ctrl键或者Shift键同时用鼠标选中多行),然后再删除。","提示");
}
}
this.DataGirdDataBind();
}
在执行到 ds.Tables["个人基本信息"].Rows[i].Delete();时,出现 未处理的“System.NullReferenceException”类型的异常出现在糖尿病系统.exe中
其他信息:未将对象引用设置到对象的实例 这个异常
由于这个系统马上就要交了,小弟在次求各位老大帮忙!
在线~~~~~~~等~~~~~~~!!!