Wednesday 8 January 2014

Login Page In ASP.Net By Using C# code

Login Page In ASP.Net By Using C# code




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"data source=saibaba-pc\server; database=Genreal; integrated security=SSPI");
        SqlCommand cmd = new SqlCommand("select * from registration where mailid=@mailid and password=@password",con);
        cmd.Parameters.AddWithValue("@mailid",TextBox1.Text);
        cmd.Parameters.AddWithValue("@password",TextBox2.Text);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            Label3.Text = "user id password invalid";
        }
    }
}

0 comments:

Post a Comment