我想为 2 种类型登录:管理员和普通用户,每个都有差异表,我将通过下拉列表检查类型,
问题:它赢得t get into if statement that check the type.
how to make it check what
了下拉列表的值,并取决于它决定检查哪个表。
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Imports System.Threading
Public Class _Default
Inherits System.Web.UI.Page
Public s As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session.Clear()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
con.Open()
Dim userCount As Int32 = GetUserCount(txtUserName.Text)
Dim paasCount As Int32 = GetPassCount(TxtPassword.Text)
Dim userCount2 As Int32 = GetUserCount(txtUserName.Text)
Dim paasCount2 As Int32 = GetPassCount(TxtPassword.Text)
Dim x As String = DrpType.SelectedValue
If x = "Admin" Then
If userCount2 > 0 And paasCount2 > 0 Then
Session("FirstName") = txtUserName.Text
Response.Redirect("LoggedIn.aspx")
ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Admin')", True)
Else
lblErr.Visible = True
End If
ElseIf x = "Cus" Then
If userCount > 0 And paasCount > 0 Then
Session("FirstName") = txtUserName.Text
Response.Redirect("LoggedIn.aspx")
ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Customer')", True)
Else
lblErr.Visible = True
End If
End If
End Sub
' Method to check existence for users
Public Shared Function GetUserCount(ByVal userName As String) As Int32
Const sql1 = "SELECT COUNT(*) FROM Registration where username = @UserName"
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
Using cmd = New SqlCommand(sql1, con)
cmd.Parameters.AddWithValue("@UserName", userName)
con.Open()
Using reader = cmd.ExecuteReader()
If reader.HasRows Then
reader.Read()
Dim count As Int32 = reader.GetInt32(0)
Return count
End If
End Using
End Using
End Using
End Function
' Method to check PAssword for users
Public Shared Function GetPassCount(ByVal password As String) As Int32
Const sql2 = "SELECT COUNT(*) FROM Registration where password = @Password"
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
Using cmd = New SqlCommand(sql2, con)
cmd.Parameters.AddWithValue("@Password", password)
con.Open()
Using reader = cmd.ExecuteReader()
If reader.HasRows Then
reader.Read()
Dim count As Int32 = reader.GetInt32(0)
Return count
End If
End Using
End Using
End Using
End Function
' Method to check existence for admin
Public Shared Function GetUserCount2(ByVal userName2 As String) As Int32
Const sql3 = "SELECT COUNT(*) FROM Adm_Login where username = @UserName"
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
Using cmd = New SqlCommand(sql3, con)
cmd.Parameters.AddWithValue("@UserName", userName2)
con.Open()
Using reader = cmd.ExecuteReader()
If reader.HasRows Then
reader.Read()
Dim count As Int32 = reader.GetInt32(0)
Return count
End If
End Using
End Using
End Using
End Function
' Method to check PAssword for admin
Public Shared Function GetPassCount2(ByVal password2 As String) As Int32
Const sql4 = "SELECT COUNT(*) FROM Adm_Login where password = @Password"
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
Using cmd = New SqlCommand(sql4, con)
cmd.Parameters.AddWithValue("@Password", password2)
con.Open()
Using reader = cmd.ExecuteReader()
If reader.HasRows Then
reader.Read()
Dim count As Int32 = reader.GetInt32(0)
Return count
End If
End Using
End Using
End Using
End Function
Public Sub DrpType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DrpType.SelectedIndexChanged
End Sub
End Class