kalpesh says:
NoorAhmed2 says:
Dim
dt
As
DataTable = objM.FindPass()
You need to find what Data returning from this Datatable if EmailId and password matched. Check your Function Functionality if you are passing EmailId and password then is it working correctly to return the Datatable. As you are using UserControl for Login and Logout functionality you need to sure set any session value if user successfully login and when user logout from using Usercotrol you need to End the session by using Session.Abandon() and in page load of UserControl check if session is Null then you need to redirect to default page which is accessible for NonLogin user. If your login functionality is working fine then Refer the below link for your reference you just need to redirect to any default page which is accessible to Non Login User and if user is login then just sets the session as true and on logout you need to set is as null also on logout method just end the session and on PageLoad of UserControl code you need to check the Session value if its null then redirect to default page.
Hi kalpesh,
I have applied your code and have worked with me , Thank You
Protected Sub LinkButtonLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonLogout.Click
LinkButtonLogin.Visible = True
LinkButtonLogout.Visible = False
LabelNameMember.Visible = False
LinkButtonRegister.Visible = False
Response.Redirect("~/Login-Member.aspx")
End Sub
My login is true and there is no problem with it . The problem is only in finding one row of the database for that member who is logged on by his Email Like ID !
These functions that called :
Public Function FindPass() As DataTable
Getconnection()
Dim SQL As String = "SELECT * from Member where Email=@Email and Password=@Password "
Dim dt As New DataTable
Dim da As New SqlDataAdapter(SQL, conn)
da.SelectCommand.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email
da.SelectCommand.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Password
da.SelectCommand.Parameters.Add("@EnglishName", SqlDbType.NVarChar).Value = EnglishName
Try
da.Fill(dt)
Catch ex As Exception
'Error
Finally
conn.Close()
End Try
Return dt
End Function
Public Function FindMember() As SqlDataReader
Getconnection()
Dim comm As SqlCommand
comm = New SqlCommand("select * from Member where Email=@Email and Password=@Password ", conn)
Dim reader As SqlDataReader
comm.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email
comm.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Password
reader = comm.ExecuteReader()
'reader = comm.ExecuteReader(CommandBehavior.CloseConnection)
reader.Read()
EnglishName = reader.Item("EnglishName").ToString
reader.Close()
conn.Close()
Return reader
End Function
Public Function FindMebPage() As DataTable
Getconnection()
Dim sql As String = "SELECT Member.MemberID,Member.EnglishName,Member.ArabicName,Member.MemberImage,Member.DateOfMembership,Member.Email,Member.Phone,Member.CityID,Member.PCTLEVELID,MEmber.ISIDLEVELID,Member.SBLEVELID,Member.CategoryID,Member.PCTID,Member.ISIDID,Member.SBSID,Member.CountryID,Country.CountryName,City.CityName,Category.CateName,PCTLEVEL.PCTName,PCTLEVEL.PCTNote,ISIDLEVEL.ISIDNote,SBLEVEL.SBSNote,ISIDLEVEL.ISIDName,SBLEVEL.SBName FROM Member,City,Category,Country,PCTLEVEL,ISIDLEVEL,SBLEVEL Where City.CityID=Member.CityID AND Member.CountryID = Country.CountryID AND Category.CategoryID = Member.CategoryID AND PCTLEVEL.PCTLEVELID =Member.PCTLEVELID AND ISIDLEVEL.ISIDLEVELID =Member.ISIDLEVELID AND SBLEVEL.SBLEVELID =Member.SBLEVELID "
Dim dt As New DataTable
Dim da As New SqlDataAdapter(sql, Me.conn)
If CountryID <> 0 Then
da.SelectCommand.CommandText &= "AND City.CountryID = @CountryID"
da.SelectCommand.Parameters.Add("@CountryID", SqlDbType.Int).Value = CountryID
End If
If PCTID <> "" Then
da.SelectCommand.CommandText &= " AND Member.PCTID Like @PCTID"
da.SelectCommand.Parameters.Add("@PCTID", SqlDbType.NVarChar).Value = "%" & PCTID & "%"
End If
If ISIDID <> "" Then
da.SelectCommand.CommandText &= " AND Member.ISIDID Like @ISIDID"
da.SelectCommand.Parameters.Add("@ISIDID", SqlDbType.NVarChar).Value = "%" & ISIDID & "%"
End If
If SBSID <> "" Then
da.SelectCommand.CommandText &= " AND Member.SBSID Like @SBSID"
da.SelectCommand.Parameters.Add("@SBSID", SqlDbType.NVarChar).Value = "%" & SBSID & "%"
End If
If CityID <> 0 Then
da.SelectCommand.CommandText &= " AND Member.CityID =@CityID"
da.SelectCommand.Parameters.Add("@CityID", SqlDbType.Int).Value = CityID
End If
If MemberID <> "" Then
da.SelectCommand.CommandText &= "AND Member.MemberID Like @MemberID"
da.SelectCommand.Parameters.Add("@MemberID", SqlDbType.NVarChar).Value = "%" & MemberID & "%"
End If
If EnglishName <> "" Then
da.SelectCommand.CommandText &= " AND Member.EnglishName Like @EnglishName"
da.SelectCommand.Parameters.Add("@EnglishName", SqlDbType.NVarChar).Value = "%" & EnglishName & "%"
End If
If ArabicName <> "" Then
da.SelectCommand.CommandText &= " AND Member.ArabicName Like @ArabicName"
da.SelectCommand.Parameters.Add("@ArabicName", SqlDbType.NVarChar).Value = "%" & ArabicName & "%"
End If
If CategoryID <> 0 Then
da.SelectCommand.CommandText &= " AND Member.CategoryID = @CategoryID"
da.SelectCommand.Parameters.Add("@CategoryID", SqlDbType.Int).Value = CategoryID
End If
If PCTLEVELID <> 0 Then
da.SelectCommand.CommandText &= " AND Member.PCTLEVELID = @PCTLEVELID"
da.SelectCommand.Parameters.Add("@PCTLEVELID", SqlDbType.Int).Value = PCTLEVELID
End If
If ISIDLEVELID <> 0 Then
da.SelectCommand.CommandText &= " AND Member.ISIDLEVELID = @ISIDLEVELID"
da.SelectCommand.Parameters.Add("@ISIDLEVELID", SqlDbType.Int).Value = ISIDLEVELID
End If
If SBLEVELID <> 0 Then
da.SelectCommand.CommandText &= " AND Member.SBLEVELID = @SBLEVELID"
da.SelectCommand.Parameters.Add("@SBLEVELID", SqlDbType.Int).Value = SBLEVELID
End If
Try
Getconnection()
da.Fill(dt)
Catch ex As SqlException
Me.Msg = "Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
Return dt
End Function