Hi all,
I am designing a log in page and every day i face a new problem :'(
The code now is working fine but i want to add exception to check if the Login Id and the password are not exist in the DB table
I tried to put this code but it didn't work
Dim result As Data.SqlClient.SqlDataReader = dr(Data.CommandBehavior.CloseConnection)
If result.HasRows = False Then
MsgBox("Error")
Else
////the rest of the code
end if
My code
Public Sub LogIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\sony\Documents\Visual Studio 2010\Projects\SADA\SADA\App_Data\SADA2.mdf';Integrated Security=True;User Instance=True"
Dim sqlconnet As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
Dim dr As SqlDataReader
Dim UserType As String
Dim Pateint As String
Dim SLP As String
Dim Admin As String
Dim logID As String
Dim PassW As String
sqlconnet = New Data.SqlClient.SqlConnection()
sqlconnet.ConnectionString = connStr
MyComm = New Data.SqlClient.SqlCommand("", sqlconnet)
MyComm.CommandType = Data.CommandType.Text
MyComm.CommandText = "SELECT * FROM LoginTable WHERE (loginId ='" & TextBox1.Text & "') AND (Password = '" & TextBox2.Text & "') "
sqlconnet.Open()
dr = MyComm.ExecuteReader()
dr.Read()
'Dim result As Data.SqlClient.SqlDataReader = dr(Data.CommandBehavior.CloseConnection)
'If result.HasRows = False Then
' MsgBox("Error")
'Else
logID = dr.GetInt32(0)
PassW = dr.GetInt32(1)
UserType = dr.GetString(5)
Select Case (UserType)
Case "S"
SLP = dr.GetInt32(3)
Response.Redirect("SLPMain.aspx")
Case "A"
Admin = dr.GetInt32(2)
Response.Redirect("Admin.aspx")
Case "P"
Pateint = dr.GetInt32(4)
Response.Redirect("WebForm4.aspx")
End Select
End Sub
Plz Help!!
Thanks in advance