SQL Con
SQL Con
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.VisualBasic;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd =con.CreateCommand();
con.Open();
cmd.CommandText="INSERT INTO Emp VALUES('"+TextBox1.Text
+"','"+TextBox2.Text+"')";
cmd.Connection=con;
int flag= cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Insterted successfuly");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect(Request.RawUrl);
}
protected void Button4_Click(object sender, EventArgs e)
{
String inp=Interaction.InputBox("Enter the id ","Search","",0,0);
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "DELETE from Emp where Id=" +inp ;
cmd.Connection = con;
int flag = cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Deleted successfuly");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "UPDATE Emp set Name ='" + TextBox2.Text + "' where Id = " +
int.Parse(TextBox1.Text);
cmd.Connection = con;
int flag = cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Updated successfuly");
}
}
}