hi everyone kindly help me with my code, my form isn't showing my newly added records in the database but when i close it and then open again it will show. I want to know how to add refresh button and it will automatically refresh itself..


Thanks in advance!

how are you showing your database records on your form?
you may use a timer tick option for refreshing page after a specified amount of time and fill your form again from the database.
show some of your code so that someone can help you better.

if you are using a gridview just get the data from the db and rebind the gridview as you do when you open the form the first time.
refreshing the whole page(although i use it) gives an awful flickering that u can't get rid of.

Declare these stuffs first:

Dim Conn As New OleDbConnection
    Dim Cmd As New OleDbCommand()
    Dim da As New OleDbDataAdapter(Cmd)
    Dim dt As New DataTable
    Dim ds As New DataSet

Here's how I display my database records using datagridview

Private Sub AdminConsole_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Cmd = New OleDbCommand("SELECT * FROM staffs", New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source =KDE.mdb;"))
        Me.da = New OleDbDataAdapter(Me.Cmd)
        Me.ds = New DataSet()

        Me.Cmd.Connection.Open()
        Me.da.Fill(Me.ds)
        Me.Cmd.Connection.Close()

        Me.dataGridAdmin.DataSource = Me.ds.Tables(0).DefaultView
    End Sub

And here's the code for my Refresh Button.

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Me.Cmd = New OleDbCommand("SELECT * FROM staffs", New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source =KDE.mdb;"))
        Me.da = New OleDbDataAdapter(Me.Cmd)
        Me.ds = New DataSet()

        Me.Cmd.Connection.Open()
        Me.da.Fill(Me.ds)
        Me.Cmd.Connection.Close()

        Me.dataGridAdmin.DataSource = Me.ds.Tables(0).DefaultView
    End Sub

hi how about this code of mine?

this is my declaration

Dim inc As Integer
    Dim con As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand()
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim sql As String
    Dim MaxRows As Integer

and ...

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Documents and Settings\JIM\My Documents\Visual Studio 2010\Projects\hrisbyith\hrisbyith\PersonnelQMDB.mdb"

        con.ConnectionString = dbProvider & dbSource

        con.Open()
        sql = "SELECT * FROM Personnel"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "Perinfo")

        con.Close()

can u make the refresh button for me?

tnx

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