开发者

Fail to bind accdb to combobox in wpf

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜