Hi, i would like to know how to refresh data base after i insert records. I explain, i have form in which user add data into database ACCESS, after that if he would like to view all data he got it but without the latest added, so i was obliged to close application and reopen it, this is not useful :(
i tried to use form.refresh() method but seems not to work with my purpose.
thanks in advance for help ;)

Hi, what function/subroutine you talk about :)
what should my function do ?? close and open data base ?
thx in advance ;)

after i insert records. I explain, i have form in which user add data into database ACCESS, after that if he would like to view all data he got it but without the latest added, so i was obliged to close application and reopen it, this is not useful

You have mentioned that your user had insert records. Then, to only way is to use the function that gets the data again.

Lets say you start a program and automatically it shows the current data in Access, this getting the current data should be named as "Function A" (Actually for easy reference, you should call it GetData or whatever you deem appropirate).

Then your user went to insert / update records. This insert / update record has to be done in some other functions / subroutine in your code.

So now you have updated the database, but you cannot see the updated result, because the retrieved datagridview etc data controls is not synchronize with Access (Or your database such as SQL, for other's benefit.)

Hence, you should call that "Function A" you have loaded during the start of your application. In the case where you have put this section on Load Event / Public Sub New() part, you should extract this getting database's details onto another subroutine / function depending if that returns a value (Again, it is up to your preference, you may update your datagridview etc data controls within the subroutine, or return as a new dataset so that different functions can use it for different purpose.). Subroutine is used when NOT returning any value.

For your sake, i put an example code.

Public Sub New()
LoadDB()
End Sub
Public Sub LoadDB()
'Code for setting the connection string is omitted.
command.CommandText = "" 'Fill in the Access DB command text yourself in between of the 2 quotes. 
conn.Open()
Dim da As New OleAdapter(command)
Dim ds As New DataSet
da.Fill(ds,"YourTableName")
conn.Close
'Databind your datagridview / gridview etc data controls into this ds, or using this ds to load your combobox etc. This is out of scope.
End Sub
Public Sub Update()
'Code for setting the connection string is omitted.(You may declare "command" and "conn" as public shared variable, so that the connection string is only loaded in application's startup, in the New() subroutine. This will minimize repeating codes.
) 
command.CommandText = "update " 'Fill in the Access DB command text yourself in between of the 2 quotes and after "Update". (This is update database) 
conn.Open()
command.ExecuteNonQuery()
conn.Close
LoadDB()'Get the latest update again.
End Sub
Public Sub Insert()
'Code for setting the connection string is omitted. (You may declare "command" and "conn" as public shared variable, so that the connection string is only loaded in application's startup, in the New() subroutine. This will minimize repeating codes.
)

command.CommandText = "insert into " 'Fill in the Access DB command text yourself in between of the 2 quotes and after "insert into". (This is insert database) 
conn.Open()
command.ExecuteNonQuery()
conn.Close
LoadDB()'Get the latest update again.
End Sub
'The code for button click is omitted.

Edited 6 Years Ago by samuel_1991: Formatting issue.

This article has been dead for over six months. Start a new discussion instead.