VB.NET登录表单 - 使用Oracle

时间:2013-02-20 16:47:57

标签: vb.net oracle

在连接到Oracle数据库的VB.Net的登录表单中。是否有一种插入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

1 个答案:

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