.net 如何从数据库中存储的数据加载combobox中的项

.net 如何从数据库中存储的数据加载combobox中的项,.net,vb.net,combobox,.net,Vb.net,Combobox,我试图从数据库中存储的数据中加载组合框中的某些项。 我有一个按钮,当点击它填充公司的详细信息在相关框中正确。 在数据库中我有三个字段,比如 Dev = Yes or No Fin = Yes or No Net = Yes or No 其中Dev是字段名,Yes是存储在数据库中的文本 我在reader中阅读了一家公司的所有细节,所以我尝试了类似的方法 If reader(14).ToString = "Yes" then combobox1.items.add("Developer")

我试图从数据库中存储的数据中加载组合框中的某些项。 我有一个按钮,当点击它填充公司的详细信息在相关框中正确。 在数据库中我有三个字段,比如

Dev = Yes or No
Fin = Yes or No
Net = Yes or No
其中Dev是字段名,Yes是存储在数据库中的文本

我在reader中阅读了一家公司的所有细节,所以我尝试了类似的方法

If reader(14).ToString = "Yes" then
   combobox1.items.add("Developer")
else if reader(15).ToString = "Yes" Then
   combobox1.items.add("Finance")
Else if reader(15).ToString = "Yes" Then
   combobox1.items.add("Networking")
End iF

如何实现这一点没有任何想法?

试试这个,你正在检查这个条件
否则如果读卡器(15)。ToString=“Yes”然后在你的代码中
两次,这可能是你的问题

If reader(14).ToString = "Yes" then
   combobox1.items.add("Developer")
else if reader(15).ToString = "Yes" Then
   combobox1.items.add("Finance")

'--------------\/ May be this could be your problem. 
Else if reader(15).ToString = "Yes" Then     
   combobox1.items.add("Networking")
End iF
考虑一下这一点,这可能会解决您的套管问题

    If reader("Dev").ToString.ToUpper() = "YES" then
       combobox1.items.add("Developer")
    else if reader("Fin").ToString.ToUpper() = "YES" Then
       combobox1.items.add("Finance")
    Else if reader("Net").ToString.ToUpper() = "YES" Then     
       combobox1.items.add("Networking")
    End iF

使用
Equals
检查值、字段名称和条件的
ElseIf
,并检查这是否解决了问题:

If reader("Dev").ToString.Equals("yes", StringComparison.InvariantCultureIgnoreCase) Then
    ComboBox1.Items.Add("Developer")
ElseIf reader("Fin").ToString.Equals("yes", StringComparison.InvariantCultureIgnoreCase) Then
    ComboBox1.Items.Add("Finance")
ElseIf reader("Net").ToString.Equals("yes", StringComparison.InvariantCultureIgnoreCase) Then
    ComboBox1.Items.Add("Networking")
EndIf

但是,如果您在数据库中以不同的方式存储这些值会更好。例如,只能在一个字段中存储类型。例如,“开发”、“财务”或“网络”。或者更好的是,创建一个包含id、值和代码的新表,并且只使用id。

它不会加载组合框中的项目,也不会出现任何类型的错误消息…?当使用断点进行调试时,reader(14或其他)会返回什么值。?您是否检查过任何区分大小写的问题。?读卡器(14)持有“是”或“否”,控制流进入该特定的If语句。?在调试中,您是否看到它添加和项?试试combobox1.items.add(“Test”)。我已经检查过没有大小写问题。
If reader(9).ToString = "yes" Then
    ComboBox1.Items.Add("Developer")
ElseIf reader(9).ToString = "no" Then
End If
If reader(11).ToString = "yes" Then
    ComboBox1.Items.Add("Finance")
ElseIf reader(11).ToString = "no" Then
End If
If reader(10).ToString = "yes" Then
    ComboBox1.Items.Add("Networking")
ElseIf reader(10).ToString = "no" Then
End If