private void button1_Click(object sender, EventArgs e)
{
SqlCommand delcmd = new SqlCommand();
string empid = Convert.ToString("@empid");
while (true)
{
if (dataGridView1.Rows.Count > 1 && dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count - 1 )/////////////error
{
delcmd.CommandText = "DELETE FROM registrationn WHERE empid=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
con.Open();
delcmd.Connection = con;
delcmd.ExecuteNonQuery();
con.Close();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
MessageBox.Show("Employee deleted");
}
}