Link to home
Start Free TrialLog in
Avatar of andyd70
andyd70Flag for Australia

asked on

Refresh data in a Bound datagridview VB.NET

I have a datagridview in a Windows Forms Vb.NET App. The datagridview is filled in the following manner.
Dim daLines As New SqlDataAdapter("Select L.CIV_LINE_ID, L.CIV_HD_ID, L.LINE_NO, L.PRODUCT_CODE from IMPORTED_CIV_LINES L  WHERE L.CIV_HD_ID = '" & grdInvoiceList.CurrentRow.Cells(7).Value.ToString & "'", dbacotconn)

        daLines.Fill(dslines, "LINES")
        grdLines.DataSource = dslines
        grdLines.DataMember = "LINES"

As I do some cell formatting the dslines is declared as a public var.
The datagridview is filled when the user selects a row in another grid.
What I have found is that the datagridview is not clearing. The results are appending to the results of the last time it was filled. I thought I would then perhaps try to delete the contents of the datagridview and re-fresh/re-read when the DA Filled the DS. I cannot get this to work.
Can anybody provide me an easier way of refreshing data in a datagridview from a Dataset ???
Avatar of appari
appari
Flag of India image

add the following lines before daLines.Fill(dslines, "LINES")


if not dslines is nothing then
dslines.dispose
dslines = nothing
endif
dslines = new dataset
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyd70

ASKER

I know that i have tried this before, The Problem was that it failed initially. I put the Table.Clear inside a Try Catch block and all worked.

Thank you for your help