如何在VB.NET中使用来自Access数据库的数据解除绑定和重新绑定列表框? [英] How to unbind and rebind listbox with data from access database in VB.NET?
本文介绍了如何在VB.NET中使用来自Access数据库的数据解除绑定和重新绑定列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以用数据库中的数据填充列表框,但是在解除绑定和重新绑定后我无法刷新列表框项。当我重新绑定listbox1时,它会添加或累积所有项目并且它不会刷新,它只是添加。
我尝试过:
这是在填写列表框中
I can fill the listbox with data from database, but I cannot refresh the listbox items after unbinding and rebinding. When I rebind the listbox1, it adds or accumulate all items and it does not refresh, it was just adding.
What I have tried:
This is the in filling listbox
<pre> provider = "Provider=Microsoft.Ace.Oledb.12.0;"
dbtblats = "Data Source =ATSDatabase.accdb;"
tblatsconnection.ConnectionString = provider & dbtblats
tblatsconnection.Open()
SqlQuery = "SELECT * FROM ATS"
datblats = New OleDb.OleDbDataAdapter(SqlQuery, tblatsconnection) '
datblats.Fill(dstblats, "ATS")
tblatsconnection.Close()
Me.ListBox1.DataSource = dstblats.Tables("ATS")
Me.ListBox1.DisplayMember = "FullNameCN"
我尝试使用此代码解除绑定并使用新数据重新绑定数据:
I tried this code to unbind and rebind data with new data:
<pre> Listbox1.DataSource = Nothing
provider = "Provider=Microsoft.Ace.Oledb.12.0;"
dbtblats = "Data Source =ATSDatabase.accdb;"
tblatsconnection.ConnectionString = provider & dbtblats
tblatsconnection.Open()
SqlQuery = "SELECT * FROM ATS WHERE DateProcessed IS NULL ORDER BY DateReceived DESC"
datblats = New OleDb.OleDbDataAdapter(SqlQuery, tblatsconnection) '
datblats.Fill(dstblats, "ATS")
tblatsconnection.Close()
Me.ListBox1.DataSource = dstblats.Tables("ATS")
Me.ListBox1.DisplayMember = "FullNameCN"
推荐答案
DataAdapter.Fill Method(System.Data.Common)| Microsoft Docs [ ^ ] 将新行添加到现有集合。您需要先清除适配器表。
The DataAdapter.Fill Method (System.Data.Common) | Microsoft Docs[^] adds the new rows to the existing set. You need to clear your adapter tables first.
这篇关于如何在VB.NET中使用来自Access数据库的数据解除绑定和重新绑定列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文