|
Question : 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 ???
|
|
Answer : Refresh data in a Bound datagridview VB.NET
|
|
... or just
dslines.Tables("LINES").Clear
The problem is not in the DataGridView, it is in the DataTable. The DataAdapter's .Fill method just adds, to any existing records in a DataTable, those covered by its current SELECT statement which are not already present. So you need to get rid of existing records from the DataTable before re-filling it.
Roger
|
|
|
|