Solved

VB.net Windows Form Refreshing data in a DataGridView

Posted on 2011-09-14
2
278 Views
Last Modified: 2012-05-12
Hi

I am running the following procedire after I make cahnges to my database
to refresh the DataGridView but it isn't refreshing
I use code
 Call Fill_Supplier_DGV()
            Me.Supplier_DataGridView.Refresh()
but even the refresh doesn't work. Should I delete everything first? How would I do this?
Sub Fill_Supplier_DGV()
        Try


            Dim sSQL As String

            sSQL = "SELECT * FROM Suppliers"

            Dim connection As New OleDbConnection(ConnectionString)
            Dim dataadapter As New OleDbDataAdapter(sSQL, connection)
            Dim ds As New DataSet()
            connection.Open()
            dataadapter.Fill(ds, "Suppliers_table")
            connection.Close()
            Me.Supplier_DataGridView.DataSource = ds
            Me.Supplier_DataGridView.DataMember = "Suppliers_table"

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

Open in new window

0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36534901
You need to empty the datagrid before resetting the DataSource. Set the DataSource to Nothing before reassigning a new value to it:
Me.Supplier_DataGridView.DataSource = Nothing
Me.Supplier_DataGridView.DataSource = ds

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 36535125
Great. Thanks very much
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question