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中
其他信息:未将对象引用设置到对象的实例 这个异常
由于这个系统马上就要交了,小弟在次求各位老大帮忙!在线~~~~~~~等~~~~~~~!!!
{
//
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中
其他信息:未将对象引用设置到对象的实例 这个异常
由于这个系统马上就要交了,小弟在次求各位老大帮忙!在线~~~~~~~等~~~~~~~!!!
{
//DataSet ds = new DataSet();
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.DeleteCommand =
da.Update(ds.Tables["个人其他信息"]);
ds.Tables["个人其他信息"].AcceptChanges();
this.DataGirdDataBind();
}
}
else
{
MessageBox.Show("请先用鼠标点击左边灰色部分选择要删除的"+
"行(可以按住Ctrl键或者Shift键同时用鼠标选中多行),然后再删除。","提示");
}
}
//当执行da.Update(ds.Tables["个人其他信息"]); 时 出现
// 未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中
//
// 其他信息:当传递具有已删除行的 DataRow 集合时,更新要求有效的 DeleteCommand。各位老大,求你们帮忙了,在线等!谢谢啦!
DataRow dr=((DataRowView)bm.Current).Row;
((DataTable)(this.dg.DataSource)).Rows.Remove(dr);
删除用这个方法就可以了