如何将ComboBox链接到SQL数据源 [英] How do I link a ComboBox to a SQL DataSource

查看:125
本文介绍了如何将ComboBox链接到SQL数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好,

我正在使用visual studio 2008创建一个基于Windows窗体的应用程序。

我正在慢慢掌握所有数据集,绑定源,表适配器的东西。



我正在尝试在我的表单中添加一个组合框并从查找表中填充它。

然后将选定的ID保存回数据表,这让我感到疯狂。

我在数据绑定模式属性对话框中尝试了我能想到的所有组合,但它仍然无法正常工作。



为简化起见,我创建了一个表单项目,并将数据源树(数据集)中的事务记录ID字段拖到表单上。



接下来,我将数据源树(数据集)中的下拉列表(相同的事务表)的ID字段拖到表单上。



逻辑上我现在需要告诉组合框根据当前选择的查找表显示提交的描述交易记录中的ID。



到目前为止我找到的所有示例都有直接编辑代码的说明。这似乎是一个简单的GUI操作。



组合框对话框有4个字段。

数据源

显示会员

超值会员

选择价值



我假设我只需要正确设置这四个它的工作原理。我尝试过每一个我能想到的组合。当表单上显示有效记录并且下拉列表中的正确文本描述或下拉列表中显示的ID而不是文本时,我要么没有初始值。

它似乎也似乎如果我尝试在下拉菜单中更改/设置一个值,那就挂起。



我出错的任何想法和/或有没有人知道一个不错的解释如何正确使用这个?



在此先感谢

David

解决方案

< blockquote>从这里开始: http://stackoverflow.com/questions/17960283/how-to-get-data-from-sql-database-to-store-in-combo-box-c-sharp [ ^ ]

Hi Guys,
I'm creating a Windows Forms based application using visual studio 2008.
I'm slowly getting the hang of all the Dataset, Binding Source, Table Adapter stuff.

I'm trying to add a Combo box to my form and populate it from a lookup table.
Then save the selected ID back to the data table and it is driving me insane.
I have tried every combination I can think of in the "Data Binding Mode" properties dialog and it still doesn't work properly.

To simplify things I have created a one form project and dragged Transaction Record ID field from the Data Sources tree (Dataset) onto the form.

Next I dragged the ID Field of the drop down list (same transaction table) from the Data Sources tree (Dataset) onto the form.

Logically I now need to tell the combo box to display the description filed from the look up table based on the currently selected ID in the transaction record.

All of the examples I have found so far have descriptions for editing the code directly. This seems like a simple GUI thing to do.

The Combo box dialog has 4 fields.
Data Source
Display Member
Value Member
Selected Value

I assume I just need to set these four correctly for it to work. I have tried every combination I can think of. I either get no initial value when a valid record is shown on the form and the correct text description is in the drop down or the ID is shown in the Drop Down and not the text.
It also seems to hang if I try and change / set a value in the drop down.

Any ideas where I'm going wrong and / or does anyone know of a decent explanation of how to use this properly?

Thanks in Advance
David

解决方案

Start here : http://stackoverflow.com/questions/17960283/how-to-get-data-from-sql-database-to-store-in-combo-box-c-sharp[^]


这篇关于如何将ComboBox链接到SQL数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆