Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have created login page when we pass the value to it doesnt redirect to home page
it doent generates any error while executing .... i m using vb .
i dont knw what going wrong wid my code..
plz help me..
thanks in advance..

here is my code for login page . it is on login button click event.

VB
Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Welcome\Documents\Visual Studio 2010\Projects\fc\App_Data\fc.mdf;Integrated Security=True;User Instance=True")
        Dim str As String
        str = "select count(*) from r_user where eml='" & eml_txt.Text & "' and pwd='" & pwd_txt.Text & "'"

        Dim cmd As New SqlCommand(str, cn)
        cn.Open()
        cmd.ExecuteScalar()
        Session("eml") = eml_txt.Text
        If (eml_txt.Text = "admin" And pwd_txt.Text = "admin") Then
            Response.Redirect("admin.aspx")
        Else
            str = "select * from r_user where eml='" & Session("eml") & "'"

            Dim da As New SqlDataAdapter(str, cn)
            Dim dt As New DataTable
            Dim s = da.Fill(dt)

            If (s < 1) Then
                Response.Redirect("profile.aspx")
            Else

                Response.Redirect("login.aspx")
            End If

            cn.Close()

        End If
Posted
v3
Comments
There may be two problems here.

1. The conditions mentioned in if statements are not satisfied.

2. The path of page is not correct. I mean For example -

Response.Redirect("admin.aspx")

here "admin.aspx" should be at the same directory and folder as of this code file. Otherwise it can't load that page.

Please make sure point 1 is working fine by debugging line by line and point 2 by checking the paths of pages you want to redirect.
mahi0607 5-Mar-13 6:17am    
it doesnt satisfy the if conditon... it retrive 0 while debuging .. can u help me out for this?
Do u mean the below condition ?

If (s < 1) Then
You can do like below...

If (dt.Rows.Count < 1) Then

Try and let me know.
mahi0607 6-Mar-13 11:42am    
not working... still redirecting on login page and password textbox were blank..

Try this, This may help

HttpContext.Current.Response.Redirect("login.aspx", false);
 
Share this answer
 
cmd.ExecuteScalar()


That's for updating a database table without asking for any information back

You have to create a reader object, that will read the response back, and feed your command object into the reader.

myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Dim FieldCount As Integer = myReader.FieldCount
While myReader.Read()
  m_count = myReader.GetString(0)
End While

if (m_Count > 0) then
  httpcontext.current.response.redirect("home.aspx")  
end if
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900