vb.net 2008 删除数据库中的某一行
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim str As String
Dim ds As DataSet
str = DataGridView1.CurrentRow.Index
Dim i As MsgBoxResult = MsgBox("确定要删除该用户吗?", MsgBoxStyle.OkCancel, "警告")
If i = MsgBoxResult.Ok Then
Select ComboBox1.Text
Case "组立工程"
search.query("delete from T_Zuli where C_UserID = '" & str & "'")
MsgBox("已成功删除该用户!", MsgBoxStyle.OkOnly, "提示")
ds = search.query("select C_UserID,C_UserID,C_UserName from T_Zuli")
Case "照度测试"
search.query("delete from T_Zhaodu where C_UserID = '" & str & "'")
MsgBox("已成功删除该用户!", MsgBoxStyle.OkOnly, "提示")
ds = search.query("select C_UserID,C_UserID,C_UserName from T_Zhaodu")
Case "标签工位"
search.query("delete from T_Biaoqian where C_UserID = '" & str & "'")
MsgBox("已成功删除该用户!", MsgBoxStyle.OkOnly, "提示")
ds = search.query("select C_UserID,C_UserID,C_UserName from T_Biaoqian")
Case "包装工程"
search.query("delete from T_Baozhuang where C_UserID = '" & str & "'")
MsgBox("已成功删除该用户!", MsgBoxStyle.OkOnly, "提示")
ds = search.query("select C_UserID,C_UserID,C_UserName from T_Baozhuang")
Case "修理工位"
search.query("delete from T_Xiuli where C_UserID = '" & str & "'")
MsgBox("已成功删除该用户!", MsgBoxStyle.OkOnly, "提示")
ds = search.query("select C_UserID,C_UserID,C_UserName from T_Xiuli")
End Select
DataGridView1.DataSource = ds.Tables(0)
End If
If i = MsgBoxResult.Cancel Then
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
数据库是ACCESS2003的,但是我就是无法删除我选中的那一行数据,str = DataGridView1.CurrentRow.Index 是不是这一行有问题啊
[解决办法]
是str = DataGridView1.CurrentRow.Index 这行有问题, 你监视一下就知道了。
[解决办法]
改为DataGridView1.CurrentRow.Cells(0).Value
注意Cells(0)的值
[解决办法]
DataGridView1.CurrentCell.Value