private void button2_Click(object sender, EventArgs e) { con.Open(); OleDbCommand delcmd = new OleDbCommand(); //if (dataGridView1.Rows.Count > 1 && dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count-1) if(dataGridView1.SelectedRows.Count > 0 && dataGridView1.SelectedRows[0].Index!=dataGridView1.Rows.Count-1) { delcmd.CommandText = "delete from table123 where Idno=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + ""; delcmd.Connection = con; delcmd.ExecuteNonQuery(); dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index); MessageBox.Show("Row Deleted"); bind(); clear(); } else { Messagebox.show("can’t delete"); } con.close(); }
delcmd.CommandText = "delete from table123 where Idno=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)