当前位置:编程学习 > C#/ASP.NET >>

我用的是C#windows窗口设计,在datagridview中删除指定行。

我用的是C#windows窗口设计,在datagridview中删除指定行。

我想要提取datagridview里的主键在用sql语句删除,可是
int id=convert.toint32(datagridview.seleted.Rows[1].cells["g_ID"].value.tostring());
但是程序在这里出错,提示索引值有问题,我把rows[1]改成0,1,2都是一样的错误。 
--------------------编程问答-------------------- 将cells["g_ID"]改成Cells[N]试试,N代表g_id所在列数。 --------------------编程问答-------------------- 不行,不行,不行,不行,不行, --------------------编程问答-------------------- string SqlDelStr = "delete from useradmin where userid=" + this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["id"].Value.ToString() ;
dataGridView1.Rows.Remove(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex])
--------------------编程问答-------------------- 没用过这些控件....  路过了 --------------------编程问答-------------------- 还是不行,我的程序老说我索引值出错
--------------------编程问答-------------------- 试试:
int id=convert.toint32(datagridview.CurrentRow.cells["g_ID"].value.tostring());
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,