我创建了一个登录页面,该页面从我的 SQL 数据库中检索数据以允许用户登录。我还使其区分大小写并添加了一点以在用户输入错误的登录详细信息超过 3 次时终止应用程序。
但是,我为 CompanyA 准备了一张桌子,为 CompanyB 准备了一张桌子;我想从这两个表中选择数据并允许用户登录。
我还希望CompanyA 去Page1,CompanyB 去Page2。
这是从一个表中选择并转到一页的原始代码;我想尝试调整这段代码来回答我的上述问题;有任何想法吗?
Try
Dim objconnection As SqlConnection = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Cara\Documents\Visual Studio 2012\Projects\Online Portal Solutions\Online Portal Solutions\Online Portal Solutions Database.mdf;Integrated Security=True")
objconnection.Open()
Dim SelectStmt As String = "SELECT * FROM [ACustomerLogIn] WHERE Username='" & txt_cusername.Text & "' COLLATE SQL_Latin1_General_CP1_CS_AS AND Password='" & txt_cpassword.Text & "' COLLATE SQL_Latin1_General_CP1_CS_AS ;"
Dim objcommand As SqlCommand = New SqlCommand(SelectStmt, objconnection)
Dim reader As SqlDataReader = objcommand.ExecuteReader
If reader.Read Then
If txt_cpassword.Text <> reader("Password").ToString And txt_cusername.Text <> reader("Username").ToString Then
frm_2custhome.Show()
Me.Hide()
txt_cusername.Clear()
txt_cpassword.Clear()
End If
Else
Static count As Integer = 0
Dim prompt As DialogResult = MessageBox.Show("Invaild Username or Password.", "Login Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning)
Select Case prompt
Case Windows.Forms.DialogResult.Retry
txt_cusername.Text = ""
txt_cpassword.Text = ""
count += 1
If count = 3 Then
MessageBox.Show("High value of failed login attempts." & vbCrLf & "Application will be terminated for security reasons.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Stop)
End
End If
Case Windows.Forms.DialogResult.Cancel
Application.Exit()
End Select
End If
Catch ex As Exception
End Try