Thursday, 27 June 2013

ASP.NET Check existing user

ASP.NET Check existing user

CSharp code in a linkbutton click which shows wheater the user already registered or not.
Connection is opened to database server.
If user id is matched data is retreived.
If data is retreived user already exists.

CSharp.NET Code

 
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Text1.Value != “”)
{
Label1.Visible = true;
SqlConnection con = new SqlConnection(res.ConnectionString);
SqlCommand cmd = new SqlCommand(“SELECT * FROM agent WHERE userid=’” + Text1.Value + “‘”, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read( ))
{
Label1.Text = Text1.Value + ” Not Available”;
Label1.ForeColor = System.Drawing.Color.Red;
}
else
{
Label1.Text = Text1.Value + ” Available”;
Label1.ForeColor = System.Drawing.Color.Green;
}
dr.Close();
con.Close();
}
}
- See more at: http://dbakings.com/ASP/User%20Check%20Availability.aspx#sthash.uL4jaXBc.dpuf

No comments:

Post a Comment