The following is my login code for my project..
Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
'Dim sName As String
Dim sUser As String
Dim sPwd As String
Dim blnValidUser As Boolean
blnValidUser = True
Dim strConn As String = "server=YOGESH\SQLEXPRESS;Trusted_Connection=yes;database=jobbunch.mdf"
'Dim MySQL As String = "Select [Name], [Login], " & _
'"[Password] from Employees " & _
'"Where Login=@uid AND Password=@Pwd"
Dim MySQL As String = "Select [uid],[pwd] from login where uid=@uid and pwd=@pwd "
Dim MyConn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SQLCommand(MySQL, MyConn)
Cmd.Parameters.Add(New SqlParameter("@uid", uid))
Cmd.Parameters.Add(New SqlParameter("@pwd", pwd))
MyConn.Open()
Try
objDR = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
While objDR.Read()
sUser = objDR("uid")
sPwd = objDR("pwd")
'sName = objDR("Name")
End While
'Dim sText As String
'If sFirst = "" And sLast = "" Then
' blnValidUser = "False"
'Else
' blnValidUser = "True"
'Session("Name") = sUser
'End If
Catch ex As Exception
blnValidUser = "False"
'lblError.visible = "true"
'lblError.text = "Sorry Errors have occurred"
Finally
ValidateUser = blnValidUser
MyConn.Close()
End Try
End Function
Basically this code is to fetch the userid and password from the database and perform the validation for the login form.
i performed the debugging activity and after line17 the execution jumps to line 22 i.e an exception is gettin occured..
pls suggest some solution.