Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将SQL Server数据库表中的数据显示到Wpf中的组合框中?_C#_Sql Server_Wpf_Combobox - Fatal编程技术网

C# 如何将SQL Server数据库表中的数据显示到Wpf中的组合框中?

C# 如何将SQL Server数据库表中的数据显示到Wpf中的组合框中?,c#,sql-server,wpf,combobox,C#,Sql Server,Wpf,Combobox,我想将SQL Server数据库表中的数据显示到Wpf/C中的组合框中 目前我有一个表查找类型,它包含两列:SectorNumber和Description 假设此表中存储的数据为: SectorNumber Description --------------------------- 01 Antitrust 02 Civil Rights 03 Criminal 04 Tax ..

我想将SQL Server数据库表中的数据显示到Wpf/C中的组合框中

目前我有一个表查找类型,它包含两列:SectorNumber和Description

假设此表中存储的数据为:

SectorNumber   Description
---------------------------
     01        Antitrust
     02        Civil Rights
     03        Criminal
     04        Tax
     ...
我的MainWindow.xaml文件中有一个文本块和一个组合框:

<Textblock Text="Type of Justice Agencies: " Name="TypeTextBlock" ... />
<Combobox Name="TypeComboBox" 
          Loaded="ComboBox_Loaded" 
          SelectionChanged="ComboBox_SelectionChanged"
          ... />
如何在C中将SQL Server数据库表中的数据显示到组合框中


我希望组合框中的项目读作01,反垄断,02,民权等等。谢谢。

有很多例子。你有没有看过或尝试过什么?你到底尝试了什么?在谷歌上搜索如何从Sql Server绑定组合框为什么你要在问答网站上居高临下?是的,我这样做了。然后你会发现大量的例子,所以代码方面会告诉我们你尝试了什么。。?如果你想展示一些努力/代码以及存在问题的地方,本网站不是为了回答你的广泛问题。。然后我们可以提供帮助。您知道如何连接到数据库吗?如何准备sql语句?如何执行此类语句并接收数据库输出?换句话说,您知道如何使用ADO.NET库吗?这里有很多要解释的。我想OP想知道如何从数据库表中提取这些数据,而不是硬编码。此外,01应该是显示的项将int更改为string。。。新字典;->新词典;那很好。一切都有帮助。谢谢你,瓦伦丁。
Here example:      

var dict = new Dictionary<int, string>();
dict.Add(1, "01, Antitrust");
dict.Add(2, "02, Civil Rights");
dict.Add(3, "03, Criminal");
dict.Add(4, "04, Tax");
myCombobox.DataSource = new BindingSource(dict, null);
myCombobox.DisplayMember = "Value";
myCombobox.ValueMember = "Key";