Tuesday, 1 July 2014

How to Design login page in Asp.Net

Hello Friends
Today i will teach you how to design log in page in Asp.net with sql connectivity

Asp.net Coding
...........................
protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = false;
        SqlConnection con = new SqlConnection("Data Source=NIIT-PC;Initial Catalog=School;Integrated Security=True");
        con.Open();
        SqlCommand com=new SqlCommand("select count (*) from Login where Username='"+TextBox1.Text+"'and password='"+TextBox2.Text+"'",con);
        flag = Convert.ToBoolean(com.ExecuteScalar());
        if (flag == true)
        {
            Response.Redirect("~/Register.aspx");
        }
        else
        {
            Label1.Text = "incorrect user name And Password";
        }
       
        con.Close();

    }

SQl Coding

Create database School
create table login(username nvarchar(30),password nvarchar(30))
insert into login values('chetan','ravi');


Thanks

No comments:

Post a Comment