CODING OF LOGIN PAGE IN C#:
Login.aspx.cs:
Notes:-
1. You have create user interface using visual studio as in screen shot.
2. double click on login button and write down the below coding on button click event.
3.Here database name is JOB.
4. Table name is userregistration.
//first of all include all namespace
//these has been added automatically in Visual Studio.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
//connection string
SqlConnection con = new SqlConnection("server=localhost; database=JOB; Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from userregistration where username=@username and
password=@password", con);
cmd.Parameters.AddWithValue("@username", text_username.Text);
cmd.Parameters.AddWithValue("@password", Text_password.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["uid"] = dr["email"].ToString();
Session["name"] = dr["username"].ToString();
Response.Redirect("jobseeakerwelcome.aspx");
}
else
{
Label1.Text = "invalid username password ";
}
}
}
Posted By:Tanuj Kumar
Comments
Post a Comment