显示与Access数据库关联的链接数据 [英] Show Linked Data Associated With Access Database

查看:116
本文介绍了显示与Access数据库关联的链接数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我已经问过与之相关的问题(http://www.codeproject.com/Questions/606417/),问题已经解决了。现在,我有一个关于显示数据的问题。该程序目前在列表框中显示网站名称,但如何在文本框中显示网站的其他数据?在Access 2013数据库中,有关于每个网站的信息(网站链接,网站是否有移动网站/等)。当有人从列表框中选择特定项目时(通过按下查看网站信息按钮),如何设置它以显示网站的其他数据,而无需单独输入编码中的每个网站的数据(从而违背了数据库的目的)?很抱歉,如果我让这个问题混乱!

I've asked a previous question associated with this before(http://www.codeproject.com/Questions/606417/), that problem was solved. Now, I have a question about displaying the data. The program is currently displaying website names in a list box, but how do I display the website's other data in text boxes and such? In the Access 2013 database, there's information about each website (website link, whether website has mobile site/not, etc.). When someone selects a specific item from the list box (by pressing a button that says "View Website Info"), how could I set it up to display the website's other data without having to type in, individually, each website's data in the coding (thus defeats the purpose for the database)? Sorry if I've made this question confusing!

推荐答案

列表框具有非常有用的能力,可以接受任何对象作为列表项;框中显示的文本取自对象的 ToString 方法。



对于这样的东西,我会创建一个基本的信封类,它有两个属性:一个包含网站名称,另一个包含唯一标识相关记录的数据库索引。该类的构造函数将两个属性作为参数。重写 ToString 方法以返回name属性。数据库中的每个条目都有自己的信封类,每个信封都会添加到列表框的项目列表中。



如果您希望实时显示数据,请截取列表框' SelectedIndexChanged 事件,它将告诉您当用户做出选择时。或者,您可以让用户单击按钮以查看数据。在任何情况下,将 SelectedItem 框转换为您的类,检索与所选网站名称关联的数据库索引,然后使用该索引快速调用数据库以检索数据。
List boxes have the extraordinarily useful ability to accept ANY object as a list item; the text displayed in the box is taken from the object's ToString method.

For stuff like this, I would create a basic "envelope" class, with two properties: one holding the name of the website, and the other holding the database index that uniquely identifies the associated record. The constructor of the class would take both properties as parameters. The ToString method is overridden to return the name property. Each entry in the database gets its own envelope class, and each envelope is added to the list box' list of items.

If you want the data displayed real time, intercept the list box' SelectedIndexChanged event, which will tell you when the user makes a selection. Or, you can have the user click a button to see the data. In any case, convert the box' SelectedItem to your class, retrieve the database index associated with the selected website name, then make a quick call to the database using that index to retrieve the data.


这篇关于显示与Access数据库关联的链接数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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