我正在尝试使用此代码来验证删除操作。只有在输入框中输入的代码是针对超级管理员但它返回错误“位置 1 没有行”时才应该执行。任何可以提供更好的代码结构的人将不胜感激。
Private Sub btnD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnD.Click
dbProvider = "Provider=Microsoft.Ace.OLEDB.12.0;"
dbSource = "Data Source = C:\Users\Blessing\Documents\IBCARIP.accdb;Persist Security Info=False"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "select UserID from Users where UserID = 'dlass8504'"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds2, "IBCARIP")
con.Close()
If InputBox("Please input your UserID to complete operation").ToString <> ds2.Tables("IBCARIP").Rows(inc).Item("UserID").ToString Then
MsgBox("You do not posess sufficient previlegies to perfom this operation..!", MsgBoxStyle.Critical)
ElseIf MsgBox("Do you really want to Delete this Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Ok Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("IBCARIP").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
da.Update(ds, "IBCARIP")
navigaterecords()
End If
End Sub