0

このコードを使用して、削除操作を検証しようとしています。入力ボックスに入力されたコードがスーパー管理者用である場合にのみ実行されますが、「位置 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
4

1 に答える 1

0

アイデアのみ..

Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'here's code for retrieving level

    btnD.Enabled = iif(Level < 3, True, False) '-- this will disabled your delete button

End Sub

Private Sub btnD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnD.Click
Dim r As MsgBoxResult

    r = Msgbox("Do you really want to Delete this Record?", MsgBoxStyle.YesNo)
    If r = MsgBoxResult.Yes Then
        'erasing here
    End If

End Sub
于 2013-08-28T00:39:23.183 に答える