我想用postgres數據庫中的數據填充組合框,但我不能得到它的工作。鏈接WPF Combobox與Postgres數據庫值
C#代碼:
private void fill_combo()
{
string CommandText = "select ida from antenne";
using (NpgsqlConnection sqlConn = new NpgsqlConnection("server=localhost;port=5432;user=postgres;pwd=password;database=BDTelecom"))
{
sqlConn.Open();
NpgsqlCommand sqlCmd = new NpgsqlCommand(CommandText, sqlConn);
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox.Text = "ida";
}
}
XAML代碼:
<ComboBox x:Name="comboBox"
HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="170"
ItemsSource="{Binding}" />
任何想法?
數據表中要在組合框中查看的列的名稱是什麼? –
我想顯示'ida' – geocoder
如果你只是想顯示'ida',你爲什麼需要數據庫數據? –