Solved

VB.net Windows Form Refreshing data in a DataGridView

Posted on 2011-09-14
2
275 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now