WPF记录集列表框数据绑定?

时间:2013-03-01 06:35:53

标签: wpf vb.net data-binding adodb recordset

如何将我的记录绑定到列表框的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 = ?????

希望有人可以帮助我。感谢。

1 个答案:

答案 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

我没有编译它,但我希望你有这个想法