检查asp.net中的用户名和密码

时间:2014-03-23 06:19:45

标签: mysql asp.net

我尝试了很多,但一次又一次地提出同样的问题 当我输入正确的用户名和密码时,“if”阻止和“捕获”阻止,两者都在同时执行。但是,“else”块不是这种情况。 这是我的代码。

Try
            conn = New SqlConnection
            conn.ConnectionString = "Data Source=hp-hp;Initial Catalog=student;User ID=sa;pwd=student"
            conn.Open()
            comm = New SqlCommand
            comm.Connection = conn

            Dim sql As String = "SELECT * FROM intern WHERE username='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
            comm.CommandText = sql
            reader = comm.ExecuteReader
            If reader.Read() Then
                Response.Redirect("Register.aspx")
                comm.EndExecuteReader(reader)
                conn.Close()
                'Response.Redirect("Register.aspx")
            Else
                ' If user enter wrong username and password combination
                ' Throw an error message
                MsgBox("Username and Password do not match..")

                'Clear all fields
                TextBox1.Text = ""
                TextBox2.Text = ""

                'Focus on Username field
                TextBox1.Focus()
            End If

        Catch ex As Exception
            MsgBox("Failed to connect to Database..")
        End Try

感谢。

0 个答案:

没有答案