C# 将WPF组合框链接到Postgres数据库值

C# 将WPF组合框链接到Postgres数据库值,c#,wpf,postgresql,combobox,C#,Wpf,Postgresql,Combobox,我试图用postgres数据库中的数据填充一个组合框,但我无法让它工作 C#代码: XAML代码: <ComboBox x:Name="comboBox" HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="170" ItemsSource="{Binding}" /> 有什么想法吗?您正在检索数据,但没有将其分配给组合框 将dt指定为源,并设置希望用

我试图用postgres数据库中的数据填充一个组合框,但我无法让它工作

C#代码:

XAML代码:

<ComboBox x:Name="comboBox"
          HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="170"
          ItemsSource="{Binding}" />


有什么想法吗?

您正在检索数据,但没有将其分配给
组合框

dt
指定为源,并设置希望用户看到的列名

...
da.Fill(dt);
comboBox.ItemsSource = dt.DefaultView;
comboBox.DisplayMemberPath = "ida";

假设数据表中字段的名称(数据库中列的名称)为
“ida”
,并且类型为
string
,则需要执行以下操作:

comboBox.ItemsSource =
    dt.Rows
    .Cast<DataRow>()
    .Select(x => x.Field<string>("ida"));
comboBox.ItemsSource=
dt.行
.Cast()
.选择(x=>x.Field(“ida”);

dt
comboBox.ItemsSource=dt带下划线,“不可能反转换隐含项le类型'System.Data.DataTable'en'System.Collections.IEnumerable.”您想在组合框中查看的数据表中的列的名称是什么?我想显示
ida
如果您只想显示
ida
,为什么需要数据库数据?我的表名为天线,它包含两列
ida
radius
。我想将ida放在组合框中,以进行一些sql查询和计算。'DataTable'ne contient pas de deédefinition pour'itemsource'et aucune méthode d'extension'itemsource'(对不起,我的意思是说
comboBox.ItemsSource
。请参阅更新的代码。
comboBox.ItemsSource =
    dt.Rows
    .Cast<DataRow>()
    .Select(x => x.Field<string>("ida"));