If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

updating datagridview in vb 2005

i have a datagridview that gets it's data from a MS access 2003 database via a table adapter. the datagridview shows the data fine on load, however, it is there for viewing purposes only, and not editing. the editing is done via code...the only problem is, i do not know how to update the datagridview after i have changed the databse via code. If i stop and start the program again, on load the datagridview fills with the data.

I'm sorry i don't know what to do with vb again 'cause i'm using c#.
But this codes below will be not much different with vb.

Code:

/***
Before you can update the dataSet make sure you
call the EndEdit() method from the dataSet or from your
BindingSource.
*/
this.BindingContext[dataSet, "Table1"].EndEdit();
/***
You can just call the Update() method from dataAdapter which
receives one parameter that is the dataSet but you will always
have concurrency exception raised.
*/
DataSet dsToUpdate = dataSet.Table1.GetChanges();
if (dsToUpdate != null) {
dataAdapter.Update(dsToUpdate);
}
/***
This is the most safe way i think to update dataSet.
You update the dataSet by three steps.
We will use Select() method from dataSet which will return DataTable.
The Select() method receives three parameters that are
filterCriteria, sortCriteria, and DataRowViewState respectively.
If you don't want to add any filter or sort just put null.
*/
if (dataSet.HasChanges()) {
dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.Deleted));
dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.Added));
dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.ModifiedCurrent));
}
/***
After the dataset have been updated you must call the
AcceptChanges() method from the dataSet so the ModifiedCurrent
state record will be changed to Original state means that all of
your changes is commited.
*/
dataSet.Table1.AcceptChanges();
/***
References:
+---------------------|---------------+
+ vb | c# +
+---------------------|---------------+
+ Me | this +
+ () for array | [] +
+ if ..... End If | if (.....) { } +
+---------------------|---------------+
**/