我在数据网格视图上过滤我的数据时遇到问题,每当我在搜索框中搜索相同的数据时,它会在我的数据网格视图上不断添加相同的数据。我该如何解决?
我有两张相关的表格。
这是我的代码:
Dim sqlqr As String
Dim sqlqry As String
Dim src As New BindingSource()
Dim tbl As DataTableCollection = ndst.Tables
sqlqry = "SELECT * FROM tblEmployeeInfo WHERE EmpIdNo='" & txtEmpid.Text & "'"
sqlqr = "SELECT * FROM tblAttendance WHERE EmpIdNo='" & txtEmpid.Text & "'"
If sqlqr <> sqlqry Then
cnn = New OleDbConnection(cs)
da = New OleDbDataAdapter(sqlqr, cnn)
cnn.Open()
da.Fill(ndst, "tblAttendance")
Dim vw As New DataView(tbl(0))
cnn.Close()
src.DataSource = vw
dgridDtr.DataSource = src
' dgridDtr.DataMember = "tblAttendance"
src.Filter = String.Format("[EmpIdNo] LIKE '%" & txtEmpid.Text & "%'")
dgridDtr.Refresh()
End If
这里有截图: Heres The image Data Grid