在窗口客户区显示或记录数据库 [英] Display or records from database in window client area

查看:87
本文介绍了在窗口客户区显示或记录数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可用于显示数据库记录的简化方法或控件?

我通常使用LineTo和Textout函数手动创建表。这些方法很乏味。是否有更简单的方法,如使用控件或标准函数?

Are there simplified ways or controls that one can use to display records from database?
I usually manually create tables using LineTo and Textout functions. These approach is tedious.Are there easier ways like using controls or standard functions?

推荐答案

是的。使用向导创建一个新的基于Dialog的MFC应用程序。

在项目中添加CDatabase和CRecordset类。

然后可以将CDatabase类链接到单个数据库,而数据库中的每个Table都链接到每个CRecordset类。然后,您需要添加一个显示数据的控件。显示数据库表内容的最方便方法是使用网格视图。请注意,table可以是您的数据库表之一,也可以是查询。您可以附加一个查询,例如:SELECT * FROM TABLE1 WHERE LASTNAME =''Smith''作为记录集的数据源。



参见: http://msdn.microsoft.com/en-us/library/czxt1e3z% 28v = vs.71%29.aspx [ ^ ]



现在,关于您将用于显示数据库内容的控件,我建议您阅读本文:

MFC网格控件2.27 [ ^ ]



然后,假设您的Grid是通过添加到对话框中的成员变量访问的,名为m_gridctrl:



链接你的网格控制到名为mydb的MS Access数据库,使用它代码:

Yes there are. Create a new Dialog based MFC application using the Wizard.
Add a CDatabase and a CRecordset classes to your project.
The CDatabase class can then be linked to a single database, while each Table in your database is linked to each CRecordset class. You then need to add a control that will display the data. The most convinient way to display a contents of a database table would be using grid view. Please note that "table" can be one of your database''s tables but also a query. You can attached a query like: "SELECT * FROM TABLE1 WHERE LASTNAME = ''Smith''" as your data source of your recordset.

See also: http://msdn.microsoft.com/en-us/library/czxt1e3z%28v=vs.71%29.aspx[^]

Now, regarding the control you will use to display the database contents, I recomend reading this article:
MFC Grid control 2.27[^]

Then, assuming your Grid is accessed via a member variable added to your dialog box, named m_gridctrl:

To link your grid control to an MS Access Database named "mydb", use this code:
m_gridctrl.m_strDataSource = "Provider=Microsoft.Jet.OLEDB.4.0;"
    "Data Source=mydb.mdb";





要将网格控件链接到要显示的名为MyTable的实际表(记录集),请使用此代码:





To link your grid control to the actual table (recordset), named "MyTable" to be displayed, use this code:

m_gridctrl.m_strQuery = "select * from MyTable";

m_gridctrl.Bind();
m_gridctrl.FillGrid();


这篇关于在窗口客户区显示或记录数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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