You are on page 1of 3

Query for Insertion and Deletion:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DB_ass
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-4FQG153\mateen;
Initial catalog=SE; Integrated Security=true;");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd = new SqlCommand("Insert into Students values('" + txtSap.Text + "','" +
txtName.Text + "','" + txtSemester.Text + "','" + txtdept.Text + "','" + txtEmail.Text + "')");
cmd.ExecuteNonQuery();
MessageBox.Show("Data is Inserted");
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd = new SqlCommand("Delete from Students values('" + txtSap.Text + "')");
cmd.ExecuteNonQuery();
MessageBox.Show("Data is Inserted");
con.Close();
}

}
}

You might also like