开发者

Fail to bind accdb to combobox in wpf

开发者 https://www.devze.com 2023-04-11 09:37 出处:网络
I have binded the accdb to combobox but it can not bind the data currently, it can only bind the first character of first record of the table

I have binded the accdb to combobox but it can not bind the data currently, it can only bind the first character of first record of the table

for example, if the records are:

abcd xyz ijkl

the combobox will display a b c d

How to bind the data currently?

Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                            "Data Source=a开发者_如何学Pythonlbum.accdb"
Dim sql As String = "Select type from album"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sql, connStr)
Dim album As New DataTable
dataAdapter.Fill(album)
DataContext = album


<ComboBox Name="type" ItemsSource="{Binding Path=type}" />


Because you have set the DataContext to the album DataTable you use the whole DataContext as the ItemsSource (so no Path needed). And to display the type property you can use the DisplaymemberPath attribute.

<ComboBox Name="type" ItemsSource="{Binding}" DisplayMemberPath="type" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号