如何将我的记录绑定到列表框的itemssource?
cn.ConnectionString = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\mvdata.accdb;" cn.Open() If rs.State = True Then rs.Close() rs.Open("Select * from company", cn, ADODB.CursorTypeEnum.adOpenDynamic,ADODB.LockTypeEnum.adLockOptimistic) slistbox.ItemsSource = ?????
希望有人可以帮助我。感谢。
答案 0 :(得分:0)
首先按记录集中的数据填充DataTable
,然后将ListBox
的ItemsSource设置为DataTable
。像这样:
cn.ConnectionString = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\mvdata.accdb;"
cn.Open()
If rs.State = True Then rs.Close()
rs.Open("Select * from company", cn, ADODB.CursorTypeEnum.adOpenDynamic,ADODB.LockTypeEnum.adLockOptimistic)
Dim oleDbAdapter As New OleDbDataAdapter()
Dim dataTable As New DataTable()
oleDbAdapter.Fill(dataTable, rs)
slistbox.ItemsSource = dataTable
我没有编译它,但我希望你有这个想法