using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _0_3
{
  public partial class Form1 : Form
  {
     public Form1()
     {
        InitializeComponent();
     }
     private void Form1_Load(object sender, EventArgs e)
     {
        // TODO: This line of code loads data into the 'student1DataSet.stTable' table. You can move, or remove it, as needed.
        this.stTableTableAdapter.Fill(this.student1DataSet.stTable);
        dataGridView1.AutoGenerateColumns = false;
        dataGridView1.ReadOnly = true;
     }
     private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
     {
        if (dataGridView1.CurrentCell.Value.ToString().Trim() == "Delete" )
        {
           dataGridView1.ReadOnly = false;
           dataGridView1.AllowUserToDeleteRows = true;
           string strcon;
           strcon = "Data Source=RAYANEH-C5E4683\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
           SqlConnection con;
           con = new SqlConnection(strcon);
           con.Open();
           String sn;
           SqlCommand cmd = new SqlCommand();
           string sqlDel;
           sn = dataGridView1.CurrentRow.Cells[1].Value.ToString();
           sqlDel = "DELETE FROM stTable WHERE stNo = " + sn;
           cmd.CommandText = sqlDel;
           cmd.Connection = con;
           cmd.ExecuteNonQuery();
           this.student1DataSet.stTable.Clear();
           this.stTableTableAdapter.Fill(this.student1DataSet.stTable);
           dataGridView1.Update();
           con.Close();
           dataGridView1.ReadOnly = true;
        }
     }
  }
}
