0

VB.Net连接到 Oracle 数据库的登录表单中。有没有办法插入 If 语句以将不同的用户引导到不同的表单。例如,会计主页的会计或驱动程序主页的驱动程序,即使所有这些都存在ID 和密码在数据库中的一个表中。数据库中有一个POSITION字段,我想用它来区分不同用户的访问级别。这是到目前为止工作的代码:

Dim conn As New OleDb.OleDbConnection

conn.ConnectionString = _
"Provider=msdaora;Data Source=orabis;User Id=112221800;Password=112221800;"


conn.Open()

Dim parmuser As New OleDb.OleDbParameter

parmuser.OleDbType = OleDb.OleDbType.Char

parmuser.Value = txtStaffNo.Text

Dim parmpass As New OleDb.OleDbParameter

parmpass.OleDbType = OleDb.OleDbType.Char

parmpass.Value = txtPassword.Text



Dim cmd As New OleDbCommand

cmd.Connection = conn

cmd = New OleDbCommand("select STAFFID,PASSWORD from STAFF where STAFFID ='" & txtStaffNo.Text & "' and PASSWORD ='" & txtPassword.Text & "'", conn)

cmd.CommandType = CommandType.Text

Dim dr As OleDb.OleDbDataReader



dr = cmd.ExecuteReader()


If txtStaffNo.Text = "" Or txtPassword.Text = "" Then

    MessageBox.Show("You have not entered any values!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)

ElseIf dr.Read() Then

    txtStaffNo.Text = dr("STAFFID")

    txtPassword.Text = dr("PASSWORD")

    MsgBox("Access Allowed")



    CustOption.Show()
    Me.Hide()

Else

    'MessageBox.Show("Wrong Username and Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    'intCount = intCount + 1



End If
4

1 回答 1

0

在您的 SELECT 语句中,在此处添加位置,这样它将是:

cmd = New OleDbCommand("select POSITION, STAFFID,PASSWORD from STAFF where STAFFID ='" & txtStaffNo.Text & "' and PASSWORD ='" & txtPassword.Text & "'", conn)

然后在验证用户之后,您只需使用如下选择案例:

Dim empPosition as string = dr("POSITION") ' assuming it's a string here
select case empPosition.toLower
   case "driver"
      ' open driver form
   case "accountant"
       'open accountant form
    ' more case statements for other positions.
End Select
于 2013-02-21T03:48:09.053 回答