kamal dhillon

kamal dhillon

  • NA
  • 23
  • 13.4k

how can remove this error index was out of range ????????

Sep 26 2012 3:56 PM
    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");

                }
              
            }


Answers (1)