Monday, 25 April 2011

LOGIN AND LOGOUT PAGE USING APS.NET

private void button1_Click(object sender, EventArgs e)

 {
            {

                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sathya\WindowsApplication4\Database2.mdb");
                OleDbCommand cmd = new OleDbCommand("Select * From Table2 where username ='" + textBox1.Text + "' and password  ='" + textBox2.Text + "'", con);
                OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                ad.Fill(dt);
                int count = dt.Rows.Count;
                if (count == 0)
                {
                    MessageBox.Show("Invalid");
                    textBox1.Text = "";
                    textBox2.Text = "";
                }
                else
                {
                    textBox1.Text = dt.Rows[0][0].ToString();
                    textBox2.Text = dt.Rows[0][1].ToString();
                    Form2 f = new Form2();
                    f.Show();
                    this.Hide();
                }
            }
        }


// Second page load

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] != null)
        {
            Label1.Text = "success";
        }
    }

// Log out page

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Abandon();
      
        Response.Redirect("Default.aspx");
    }

No comments:

Post a Comment

back to top