DataTable userdt = new DataTable();
BindingManagerBase mybind;
private void modifyUser_Load(object sender, EventArgs e)
{
userdt = getUserinfo("select * from users");//自定义函数,返回所有纪录
DataGridview1.DataSource = userdt;
mybind = BindingContext[userdt];
} private void btn_del_Click(object sender, EventArgs e)
{
int IDPosition = this.mybind.Position;
if (IDPosition != -1)
{
//删除数据库中的行
string userId = userdt.Rows[IDPosition]["user_Id"].ToString(); //error
userUpdate("delete from user where user_Id =" + int.Parse(userId));
}
}在error出错误提示"在位置2处没有任何行",但我已经选中了一行啊,"user_Id"是数据库表中的字段。请问哪里的错误??
BindingManagerBase mybind;
private void modifyUser_Load(object sender, EventArgs e)
{
userdt = getUserinfo("select * from users");//自定义函数,返回所有纪录
DataGridview1.DataSource = userdt;
mybind = BindingContext[userdt];
} private void btn_del_Click(object sender, EventArgs e)
{
int IDPosition = this.mybind.Position;
if (IDPosition != -1)
{
//删除数据库中的行
string userId = userdt.Rows[IDPosition]["user_Id"].ToString(); //error
userUpdate("delete from user where user_Id =" + int.Parse(userId));
}
}在error出错误提示"在位置2处没有任何行",但我已经选中了一行啊,"user_Id"是数据库表中的字段。请问哪里的错误??
你看看IDPosition 是不是需要-1