如何使用访问数据库中一列的数据加载组合框? [英] How do I load a combo box with data from one column in an access database?

查看:89
本文介绍了如何使用访问数据库中一列的数据加载组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< c#>

我对编程的经验很少,但我必须创建一个包含多种表单的Windows窗体应用程序。在其中一种表单中,我需要使用来自访问数据库的信息。我有一个包含两个表的访问数据库。一张桌子叫做学生。



学生表有四列:

学生编号

学生姓名

学生邮箱

学生地址



我需要使用学生姓名栏。它有十条记录。我需要将十个名称加载到一个组合框中。一旦用户从组合框中选择一个名称,表格中的其他详细信息将显示在表单上的各种文本框中。我在将名称加载到组合框时遇到问题。名称需要在程序开头加载到组合框中。如果我要使用名称加载其他信息,我是否将数据集加载到数组中,还是直接将它们加载到组合框中?



我们非常感谢任何帮助或想法。



我的尝试:



我试图创建一个学生班,然后像这样使用它:



学生aStudent =新学生//新学生部分抛出错误

(dbReader [StudentName]。ToString());

this.cmbStudents.Items。添加(aStudent);

<c#>
I have very little experience with programming but I have to create a windows form application with multiple forms. On one of the forms I need to make use of information from an access database. I have an access database with two tables. One table is called Student.

The student table has four columns:
student number
student name
student email
student address

I need to make use of the student name column. It has ten records. I need to load the ten names into a combo box. Once the user selects a name from the combo box, the other details from the table will be displayed in various textboxes on the form. I'm having trouble loading the names into the combo box. The names need to be loaded into the combo box at the start of the program. If I'm going to use the names to load other information do I load the dataset into an array or do I load them directly into the combo box?

Any help or ideas will be very appreciated.

What I have tried:

I have tried to create a student class and then use it like this:

Student aStudent = new Student //the new Student part threw out an error
(dbReader["StudentName"].ToString());
this.cmbStudents.Items.Add(aStudent);

推荐答案

只需使用这个



just use this

this.cmbStudents.Items.Add(dbReader["StudentName"].ToString());





学生aStudent =新学生


这篇关于如何使用访问数据库中一列的数据加载组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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