I tried a lot, but giving the same problem again and again.
When i am entering correct username and password , "if" block and "catch" block ,both are getting executed at the same time. However ,it is not the case with "else" block.
Here is my code.
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
Thanks.