i hve 2 form..first for insert dat & second for preview data..i'm using datagrid to preview data from accessdatabase..

how to make datagrid automaticly load data form database after insert new data..data grid only load after i relaunch my application...do i need create refresh button or anything else??

Recommended Answers

All 12 Replies

option1 -- use a refresh button

option2 -- refresh using timer (bad idea)

why option 2 bad...it slow or ??

timer keeps executing even if you do not insert new record, so consumes system resources un-necessarily.

so how to make refresh button....

you need to query the database a fresh and populate the grid.

can u give some example...

just call the routine that is populating the grid in the REFRESH button click event.

Me.TableNameTableAdapter.Fill(Me.databasenameDataSet.Tablename)

If you using dataset from vb try this one, It`s load the database to your datagrid
put in on your refresh button

it does't work..nothing hppen ...

commented: have you written any code ? -2

how to make datagrid automaticly load data form database after insert new data..data grid only load after i relaunch my application...do i need create refresh button or anything else??

I suggest to make a function to preview data. so you can call it anywhere. after insert, edit or delete data or refresh button .

what u mean??

You said that you only can preview data on data grid when you load your form.
So the code that you using to preview data at load form, make it like procedure/function.
You just call the function to refresh datagrid from anywhere.
After insert, edit or delete data or on refresh button.

Just put your preview code into procedure/function

Public Sub RefreshDataGrid()
   ... 'Your query to preview data on datagrid
End Sub

You can call that procedure at any event to refresh data grid

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    ... 'your code to insert data
    RefreshDataGrid ' call refreshdatagrid function to refresh data on datagrid after insert statment
End Sub

Do the same thing for edit or delete event or refresh button.

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.