Output Screen Shots
![]() |
| Fig1:Table before delete |
![]() |
| Fig2:Table after delete |
Source Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WinConnectedApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGetData_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
// Create a connection object
con.ConnectionString = @"Data source=USERS35\SQLExpress;initial catalog = training1;integrated security =true";
SqlCommand cmd = new SqlCommand();
cmd.Connection=con;
cmd.CommandText="delete from employee where empid="+txtEmpId.Text;
//0 1 2 3 4
try
{
con.Open();//establishes phy link between App and DB
cmd.ExecuteNonQuery();
MessageBox.Show("Record deleted..");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State==ConnectionState.Open)
{
con.Close();
}
}
}
}

