VC/MFC中的ACCESS数据库访问实现
前些天弄一个 访问 ACCESS 数据库 的小东西,费了些力气才弄好。 虽然还有些不尽人意,但是终究还是可以用了, 在这里分享一下自己的 实现 方法和经验。 里面的东西网上都有,但是,这里的是最全的。 VC/MFC 访问 ACCESS 数据库 方法1 : 1 创建一个基于对话
前些天弄一个访问ACCESS数据库的小东西,费了些力气才弄好。
虽然还有些不尽人意,但是终究还是可以用了,
在这里分享一下自己的实现方法和经验。
里面的东西网上都有,但是,这里的是最全的。
VC/MFC访问ACCESS数据库
方法1:
1 创建一个基于对话框的应用程序。
放入两个ActiveX 控件 Microsoft ADO Data Control,version 6.0 ... 和 Microsoft DataGrid Control,Version 6.0 如果没有两个空间的话,请安装OFFICE组件。
2 为控件设置属性。
1) 为ADO Data Control 设置属性:Control -> Use Connection String -> Build
在弹出的对话框中选择 Microsoft Jet 4.0 OLE DB Provider -> 下一步 -> 在"选择或输入数据库名称"处,选择所创建的数据库文件,例如:d:/test_db/testdb.mdb。密码处默认为空,如果用户表有密码的话,输入密码,并选中"允许保存密码" -> 单击"测试连接" 如弹出"测试连接成功" 表示数据文件已经可已使用。直接确定,回到为对话框资源编辑界面。
为这一控件的:RecordSource 选项设置属性如下:
Command Type 选择 1 -adCmdText
Command Text(SQL) 中 输入SQL语句 : select * from mydb;
ADO Data Control 控件的属性就设置完成了。关闭属性设置界面。
2) 为DataGrid Control设置属性。
DataSource 列表中选择:IDC_ADODC1
关闭属性设置界面。
编译,运行。如果数据库中有数据的话,就会在DataGrid中显示出来了。
想进行其他的数据库操作的话,如下例:
接着上面的程序步骤,
为ADO Data Control 添加一个变量:m_adoDC;
为Data Grid 添加一个变量:m_adoDG;
一个按钮,双击为按钮增加函数。在函数中增加下面的代码:
CString strTem = "select * from mydb where SUserName '张三'";
//VC 6.0
m_adoDC.SetRecordResource(strTem);
m_adoDC.Refresh();
//VS 2005/VS 2008
m_adoDC.put_RecordSource(strTem);
m_adoDC.Refresh();
编译运行,效果就出来了。
PS:这种方式下,查询的效果很好,但是,进行INSERT , UPDATE , DELETE 操作的时候会出现一些错误提示:
//VC 6.0 中
对象已关闭,无法进行操作。
//VS 中
Windows has triggered a breakpoint in ...
虽然有提示,但是数据库的操作是成功的。就这个问题查遍了网络,没有人能给出解决方案,同样,我并不比他们强。
第一种方案到此结束。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. Open settings in Windows 11. You can use Win+I shortcut or any other method. 2. Go to the Apps section and click Apps & Features. 3. Find the application you want to prevent from running in the background. Click the three-dot button and select Advanced Options. 4. Find the [Background Application Permissions] section and select the desired value. By default, Windows 11 sets power optimization mode. It allows Windows to manage how applications work in the background. For example, once you enable battery saver mode to preserve battery, the system will automatically close all apps. 5. Select [Never] to prevent the application from running in the background. Please note that if you notice that the program is not sending you notifications, failing to update data, etc., you can

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

Oracle can read dbf files through the following steps: create an external table and reference the dbf file; query the external table to retrieve data; import the data into the Oracle table.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Yesterday, BotanixLabs announced that it has completed a total of US$11.5 million in financing, with participation from Polychain Capital, Placeholder Capital and others. Financing will be used to build the decentralized EVM equivalent of BTCL2Botanix. Spiderchain combines the ease of use of EVM with the security of Bitcoin. Since the testnet went live in November 2023, there have been more than 200,000 active addresses. Odaily will analyze Botanix’s characteristic mechanism and testnet interaction process in this article. Botanix According to the official definition, Botanix is a decentralized Turing-complete L2EVM built on Bitcoin and consists of two core components: Ethereum Virtual Machine

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.
