deleting a row from datagridview in window application using access database c#

ADO .Net , Csharp , window application Delhi, India
  • 10 years ago

    i want to delete a selected row from datagridview i nmy window application and the changes should reflect in the database . i use the code below

    OleDbConnection connString = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database1.accdb"); connString.Open(); string query = "SELECT * FROM emp_info"; OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString); OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter); DataTable dTable = new DataTable(); dAdapter.Fill(dTable);

            BindingSource bSource = new BindingSource();
            bSource.DataSource = dTable;
            dataGridView1.DataSource = bSource;
            DataGridViewRow removingRow = new DataGridViewRow();

    but at dataGridView1.Rows.Remove(removingRow); it gives exception saying

    argument exception was unhandled Row provided does not belong to this DataGridView control. Parameter name: dataGridViewRow

    please help me.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare