Datagridview and changing Access DB Fields

Dave_e

Member
Joined
Mar 15, 2008
Messages
6
Programming Experience
Beginner
Hi,

I'm hoping someone can help.

I'm slowly learning more about VB.Net but one thing that's confusing me and no amount of reading seems to help is my DataGridView.

I have a DatagridView on a form (created with the VS Wizard) and use the following code which allows me to update the Access DB by updating the DGV table within my form.

The code also allows me to update the DGV on the form if I update the DB manually.

VB.NET:
        Me.Validate()
        Me.Table2BindingSource.EndEdit()
        Me.Table2TableAdapter.Update(Me.Database3DataSet.Table2)

        Me.Table2TableAdapter.Fill(Me.Database3DataSet.Table2)
        DataGridView1.DataSource = Table2BindingSource
        DataGridView1.Refresh()

The thing that gets me is if I add a new Field or change an existing Fields name within access, it does not get reflected in the Form.

Is this possible or do I have to delete the existing DGV and run the wizard again to incorporate any Field changes to the Access DB?


Thanks
 
Hi

No you need not to delete, you need to re-fill the dataset table, but first make sure you clear it first. Do like this e.g, on refresh button

Me.Database3DataSet.Table2.Clear
Me.Table2TableAdapter.Fill(Me.Database3DataSet.Table2)
 
you need to re-fill the dataset table, but first make sure you clear it first.
Table adapters has the ClearBeforeFill property set to True by default. But this was not what asked about...
VB.NET:
The thing that gets me is if I add a new Field or change an existing Fields name within access, it does not get reflected in the Form.
You can use the wizard again to update the table fields used, in DGV you can remove columns or add the new bound columns you want added, or set DGV datasource first to None then back to the bindingsource.
 
Hi thanks for the replies.

I've finally managed to do what I needed even tho' I'm still not 100% on what is going between DataSets and TableAdapters etc but I'm getting there.

I've sort of worked it all out via the DataSet Designer, then Right Clicking the TableAdapter, then playing with the Query Builder.

It works and I'm happy :)


Thanks again for the pointers
 
Back
Top