新手在这里!我想从我在MySQL中为我的Visual Basic创建的表中检索数据。一直在寻找办法,但遗憾的是,我仍然无法弄清楚它是如何运作的。过程如下: 1.显示登录表单窗口 2.单击“登录”按钮后,它将通过从数据库检索数据来确定该帐户是用户还是管理员 3.它将打开另一种形式,在该形式中,它取决于帐户是否是管理员(因此我创建了2个登录表单。一个用户,另一个用于管理员)
这是我到目前为止所做的事情。任何帮助将不胜感激:)
Private Sub LoginBtn_Click(sender As Object, e As EventArgs) Handles LoginBtn.Click
Try
con.Open()
com = New MySqlCommand("SELECT id FROM accounts WHERE uname='" & txtuname.Text & "'", con)
reader = com.ExecuteReader
If reader.HasRows = True Then
reader.Close()
com = New MySqlCommand("SELECT id FROM accounts WHERE pword = '" & txtpword.Text & "'", con)
reader = com.ExecuteReader
If reader.HasRows = True Then
reader.Close()
com = New MySqlCommand("SELECT id FROM accounts WHERE account_type = '" & account_type & "'", con)
reader = com.ExecuteReader
ElseIf String.IsNullOrEmpty(txtpword.Text) Then
MsgBox("Invalid Password")
txtpword.Focus()
Else
MsgBox("Invalid Password")
txtpword.Focus()
End If
ElseIf String.IsNullOrEmpty(txtuname.Text) Then
MsgBox("Invalid Username")
txtuname.Focus()
Else
MsgBox("New User Detected. Input Password")
Form2.Show()
End If
reader.Close()
con.Close()
Catch ex As Exception
If Not con.State = ConnectionState.Closed Then
con.Close()
End If
MsgBox(ex.ToString)
End Try
End Sub