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" />
精彩评论