You are on page 1of 2

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


{
SqlConnection Cn = new SqlConnection("Data Source=.;Initial
Catalog=siraj;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into login (username,password)
values ('" + TextBox1.Text + "','" + TextBox2.Text + "')", Cn);
Cn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script> alert ('values inserted
successfully')</script>");
}
else
{
Response.Write("<script> alert ('NOT inserted
successfully')</script>");
}
Cn.Close();

}
protected void Button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("update login set password='" +
TextBox2.Text + "' where username = '" + TextBox1.Text + "'", Cn);
Cn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script> alert ('values updated
successfully')</script>");
}
else
{
Response.Write("<script> alert ('NOT updated
successfully')</script>");
}
Cn.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("delete from login where username='" +
TextBox1.Text + "'", Cn);
Cn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script> alert ('deleted
successfully')</script>");
}
else
{
Response.Write("<script> alert ('NOT deleted
successfully')</script>");
}
Cn.Close();
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}

You might also like