Update a DataGridView after appending records to an Access file

I am using the code below to append new values of a field called "symbol" in an Access table called mydata -- which is bound (via BindingSource) to a DataGridView.  The update works correctly, but I need to add code at the end that will force the DataGridView to show the new field entries.  Right now, I can only see the new record values if I restart the app.

Therefore, how can I force the BindingSource to reload(?) the revised table from the Access file?

 

        Dim i, j, recordsadded As Integer
        Dim buff(), inputsymbolstr, newsymbolstr(), oldsymbolstr() As String
        inputsymbolstr = InputBox("Enter symbols separated by commas, e.g., ABC, BDE, FGH, ...")
        newsymbolstr = Split(inputsymbolstr, ",")


        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydata.mdb"
        Dim cn As New OleDbConnection(ConnString)
        cn.Open()
        Dim qry As String
        Dim cmd As New OleDbCommand(qry, cn)
       
        qry = "SELECT * FROM [" & "mydata" & "] "
        cmd.CommandText = qry
        cmd.Connection = cn
        Dim drdata As OleDbDataReader = cmd.ExecuteReader

        Cnt = 0
        Do While drdata.Read
            Cnt += 1
            ReDim Preserve oldsymbolstr(Cnt)
            oldsymbolstr(Cnt) = drdata.Item("symbol")
        Loop
        drdata.Close()

        For j = 1 To UBound(newsymbolstr)
            If Cnt > 0 Then
                For i = 1 To UBound(oldsymbolstr)
                    If oldsymbolstr(i) = newsymbolstr(j) Then GoTo nextsymb
                Next
            End If
            qry = " INSERT INTO [" & "mydata" & "] ( symbol )"
            qry &= " VALUES (" & "'" & newsymbolstr(j) & "'" & ")"
            Dim cmd1 As New OleDbCommand(qry, cn)
            recordsadded = cmd1.ExecuteNonQuery()
nextsymb:
        Next
        cn.Close()
lep11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nepaluzCommented:
Handle the DataSourceChanged event, eg


Private Sub DataGridView1_DataSourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DataSourceChanged
    Dim MyGrid = DirectCast(sender, DataGridView)
    MyGrid.Refresh()

End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Try adding a

BindingSource1.CurrencyManager.Refresh()

at the end.
Jorge SanchezSoftware EngineerCommented:
If you used a TableAdapter to read the information into the BindingSource, try calling the Fill function again so that it reads the data from the database:
TableAdapter1.Fill(BindingSource1.DataSource)
lep11Author Commented:
Solution seemed to be for real-time data entry rather than how to update a datagridview after the Access file is modified.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.