根据用户级别验证命令

时间:2013-08-27 11:42:30

标签: vb.net ms-access-2010

我正在尝试使用此代码来验证删除操作。只有在输入框中输入的代码是针对超级管理员但它返回错误“位置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

1 个答案:

答案 0 :(得分: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