Hey guys,


I have written a code that could delete
selected row in data grid view. I gives
lots of errors.

Let me paste my code.

for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {

                        DataGridViewRow dr = dataGridView1.Rows[i];
                        if (dr.Selected == true)
                        {
                            dataGridView1.Rows.RemoveAt(i);


                            cmd.CommandText = "Delete from transact1 where C_ID ='" + i + "'";
                            cmd.ExecuteNonQuery();

                            da.Update(ds, "transact1");
                            MessageBox.Show("Deleted");
                        }
                        
                        con1.Close();
                    }

While deleting row it throws exception.
"Connection property not initialized"

I have tried opening connection in different ways
but it didn't help either.
So can anyone tell me what can possibly wrong with
this code?


Thanks
Ajinkya

if the error on deletion then I think this code help you

write tis code on datagridview

dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

On any button or any control click event write this code

DataGridViewRow row = dgv.SelectedRows[0];
    dgv.Rows.Remove(row);

and if you get error on connectionstring then show what procedure you use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.