someone please help me
to remove any desired row from datagridview and the change should
reflect in database also.this is for window forms having access database
if possible pls send a working sample as i am looking for it for past one month.
Thanks in advance
Loading
Posted Jul 20, 2010, 12:58 AM
thanks for reply but it too is not working . i guess this is the correct way but there is something missing.
when run it gives exception at
dgView.Rows.Remove(removingRow);
saying
Argument Exception was Unhandled
Row provided does not belong to this DataGridView control.
Parameter name: dataGridViewRow
please help me .
thanks
Lakitha MunasinghePosted Jul 19, 2010, 8:30 AM
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";
//create the database query
string query = "SELECT * FROM MyTable";
//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
//fill the DataTable
dAdapter.Fill(dTable);
//the DataGridView
DataGridView dgView = new DataGridView();
//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
//set the DataGridView DataSource
dgView.DataSource = bSource;
//Now you can remove the desired row (i) from your datagrid as
DataGridViewRow removingRow = new DataGridViewRow ();
dgView.Rows.Remove(removingRow);
//Now you need to get the changes back into the database. All you have to do is call the
Updatefunction of the//OleDbDataAdapterwith theDataTableas the argument to accomplish this.dAdapter.Update(dTable);
Good Luck!!!
Lakitha Munasinghe