这是我的代码,每次单击Button1,而不是刷新Datagridview时,它只会添加另一个与前一个条目重复的条目。我知道我在代码中遗漏了一些内容,它会在再次加载之前清除Datagrid中的数据。请帮忙..
Private Function LoadData_UnitProcess()
Dim UP_SQL As String = "SELECT LotNum FROM Transactions WHERE StatusID=3 ORDER BY Process_EntryDate DESC"
Dim UP_Ad As OleDbDataAdapter = New OleDbDataAdapter(UP_SQL, strCon)
UP_Ad.Fill(UP_Ds, "Transactions")
UnitOnProcess_DG.DataSource = UP_Ds.Tables(0)
With UnitOnProcess_DG
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Lot #"
.Columns(0).Width = "363"
.AllowUserToAddRows = False
End With
LoadData_UnitProcess = ""
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoadData_UnitProcess()
End Sub
Private Sub Displayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData_UnitProcess()
End Sub
答案 0 :(得分:0)
您的数据集UP_Ds可能是属性或字段。您需要在重新填充之前重置数据集,否则将内容附加到上一个数据集。
UP_Ds.Reset()
UP_Ad.Fill(UP_Ds, "Transactions")
UnitOnProcess_DG.DataSource = UP_Ds.Tables(0)