如何获取当前行数???

yayapi 2007-07-08 08:13:41
我在用2005开发系统时,需要获取DataGridView1中选中行的第一列的值,我用了一种方法,但老是出现错误,以下是我的代码,不只错在何处,如何改正: private void checkedListBox1_ItemCheck(object sender,ItemCheckEventArgs e)
{ if (this.isInit == false)
{ if (e.CurrentValue.ToString() == "Checked")
{ string selectUserId = this.ds.Tables[0].Rows[this.dataGridView1.CurrentCell.RowNumber][0].ToString();
string selectItem =this.checkedListBox1.SelectedItem.ToString();
string deleteSql = "delete from 权限清单 where userid='" + selectUserId + "' and 权限名称='" + selectItem + "'";
con.Open();
SqlCommand commd = new SqlCommand(deleteSql, this.con);
int rows = commd.ExecuteNonQuery();
con.Close();
}
else
{ try
{ string selectUserId = this.ds.Tables[0].Rows[this.dataGridView1.CurrentCell.RowNumber][0].ToString();
string selectItem = this.checkedListBox1.SelectedItem.ToString();
string insertSql = "insert into 权限清单(用户号,权限名称) values('" + selectUserId + "','" + selectItem + "')";
con.Open();
SqlCommand commd = new SqlCommand(insertSql, this.con);
int r = commd.ExecuteNonQuery();
con.close(); }
catch (Exception w)
{ MessageBox.Show(w.Message); }
}
}
}

这是报错信息:
错误1与“System.Data.DataRowCollection.this[int]”最匹配的重载方法具有一些无效参数 F:\pp\c#程序\计算机耗材管理\计算机耗材管理\Form3.cs
66 35 计算机耗材管理
错误 2 参数“1”: 无法从“System.Windows.Forms.DataGridViewRow”转换为“int” F:\pp\c#程序\计算机耗材管理\计算机耗材管理\Form3.cs 66 63 计算机耗材管理
...全文
381 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧