hie guys,

a great supportive sites i have ever seen,

i am facing a simple issue with my login windows form, which i have created, it works fine no issue, but now i want that after successful login user should be automatically redirect to home screen (windows forms) but unfortunaterly i am not finding any solution for this , now what shoud i use and the login form should automatically close after redirettion. pleaase help me . .

private void button_Login_Click(object sender, EventArgs e)
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\jumbo\My Documents\Visual Studio 2010\Projects\testingdatabase\testingdatabase\Database1.mdf;Integrated Security=True;User Instance=True");
            //SqlConnection con = Program.Getconnection;
            //SqlConnection con = Program.Getconnection;
            //SqlConnection con = Program.con;
            //SqlDataReader dr = null;
            SqlCommand cmd = new SqlCommand("select * from Login WHERE Username = '" + txtUsername.Text +"' AND Password = '" + txtPassword.Text + "'");
            cmd.Connection = conn;
                //dr = cmd.ExecuteReader();
            SqlDataReader re = cmd.ExecuteReader();
                if (re.Read())

                    MessageBox.Show("login success");
                    MessageBox.Show("inavlid username and password");
                    //catch (Exception ex)
           // }

4 Years
Discussion Span
Last Post by tinstaafl

its so simple and basic in ASP Dot Net. if user is autherised then create session and then redirect to the page you want like this:

if(tblUserReg.Rows.Count == 1)
    Session["userid"] = tblUserReg.Rows[0]["user_id"].tostring();

//here tblUserReg is the resultant table retrive from database which have user and pasword correct like textboxes and status is on
//Session["userid"] will have the id as a value which is going to be null when user logout

Please also add a condition on homepage - load event like this:

if(Session["userid"] == null || session["userid"].tostring() == "")

and on logout button click please make the session null and redirect to login page like this:

void onLogoutClick()
    session["userid"] = null;

Here's one way,

If you show the login form as a dialog, then show it in the start of your main form, you read the dialogresult to either continue or end.

Assign Button_Login as the Accept button, and assign a Cancel button on the login form.

in your authentication code, if the user is authenticated just return, otherwise call the cancel button performclick method

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.