如何在VC中建立一个数据库 CDaoDatabase::Create...or use ado... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CDataBase database ;database.OpenEx( _T( "DSN=MYDATASOURCE;UID=JOES;PWD=MYPASSWORD" ), CDatabase::openReadOnly | CDatabase::noOdbcDialog );CString szSQL = "create table ..." ;//会SQL语句就行,database.ExecuteSQL(szSQL) ; 想处理数据库的话,用到两个mfc类,cdatabase,crecordset,很方便的 HOWTO: Create an .MDB File for Microsoft Access Databases ID: Q149558 --------------------------------------------------------------------------------The information in this article applies to:The Microsoft Foundation Classes (MFC), included with:Microsoft Visual C++ for Windows, 16-bit edition, versions 1.51, 1.52 Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0, 6.0 The Microsoft ODBC Desktop Driver Pack version 2.0 Data Access Pack version 3.5 Microsoft 3.0 ODBC SDK--------------------------------------------------------------------------------SUMMARYPrior to the release of the Microsoft ODBC Desktop Driver Pack version 2.0, there was no way to programmatically create a Microsoft Access database (an .mdb file). For more details about this, please see the following article in the Microsoft Knowledge Base: Q118609 HOWTO: Create an .MDB File for Microsoft Access Databases With the release of the version 2.0 driver pack and higher, MFC ODBC applications can now create .mdb files. Additionally, with the incorporation of DAO into Visual C++ 4.x or higher, you have another way to create Microsoft Access databases programmatically. MORE INFORMATIONUsing the Microsoft Access ODBC Driver to Create .MDB FilesKyle Geiger's book "Inside ODBC" provides a sample program, ODBCACC, that nicely demonstrates how to use the ODBC installer DLL API function SQLConfigDataSource to create an .mdb file. The syntax of the function call is: BOOL SQLConfigDataSource(hwndParent, fRequest, lpszDriver, lpszAttributes) Where: hwndParent is either NULL if no dialogs are to be displayed or a valid hwnd to act as parent to any driver generated dialogs. fRequest is ODBC_ADD_DSN to specify creation of the .mdb file. lpszDriver is Microsoft Access Driver (*.mdb). lpszAttributes is "CREATE_DB=<path><filename>.mdb <sort order>\0" where the <path><filename> combination identifies where the file should be created and <sort order> is language sorting order (for example, General). <path> must be specified even if the .mdb is to be created in the current working directory. Use standard relative path syntax. NOTE: Unlike most other ODBC API functions, SQLConfigDataSource returns a boolean value. This return value is TRUE if the .mdb was created, FALSE if creation failed. To use the installer DLL functions, you must: Use #include <ODBCINST.H>.Link with Odbcinst.lib for 16-bit applications.Link with Odbccp32.lib for 32-bit applications. NOTE: The functionality of SQLConfigDataSource is available through the ODBC Administrator. If you choose to add a new Microsoft Access datasource, the driver dialog includes a Create button that you can use to create an .mdb file interactively. Using DAO to Create .MDB FilesDAO allows applications developed with Visual C++ 4.x to interface with the Microsoft Jet database engine directly. This allows more efficient manipulation of Microsoft Access objects than can be achieved through ODBC, including the creation of .mdb files. For a sample program that demonstrates how to create databases and other objects, search the Microsoft Knowledge Base for the DAOTABLE sample. Sample CodeUse of SQLConfigDataSource ODBC installer DLL API function: BOOL fCreated;fCreated = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", "CREATE_DB=.\\ATest.mdb General\0" ); This will create ATest.mdb in the application's working directory using general sorting. REFERENCES"Inside ODBC" by Kyle Geiger, Microsoft Press ISBN 1-55615-815-7. For more information, please see the following article in the Microsoft Knowledge Base in the ODBC collection: Q126606 INFO: Accessing CREATE_DB, REPAIR_DB, and COMPACT_DB Additional query words: data base creation creating kbvc151 kbvc152 kbvc200 kbvc210 kbvc220 kbvc400 kbvc500 kbvc600 Keywords : kbprg kbDAO kbDatabase kbMFC kbODBC kbVC kbGrpVCDB Version : winnt:2.0,2.1,2.2,4.0,4.1,4.2,5.0,6.0 Platform : winnt Issue type : kbhowto Technology : kbvc Last Reviewed: February 16, 2000© 2000 Microsoft Corporation. All rights reserved. Terms of Use. --------------------------------------------------------------------------------Send feedback to MSDN.Look here for MSDN Online resources. 关于对话框关闭后出错的紧急求助 请教如何HOOK住TextOut 编译链接错误信息,大家帮看下 菜鸟问题!不知道如何执行一种源代码~~~~ 匪夷所思:在编辑环境中执行没问题,但直接运行生成的可执行程序却不行 求救,C++里随机产生一个8位的十六进制数! 如何编程设置本机IP地址、子网掩码、默认网关等? 存盘时 ASERT错误!!提示是wincore.cpp的958行的asert..... 程序员2001合钉版的光盘里面怎么没有第六期的杂志???? vc助手,字体颜色 一个关于多线程的菜鸟问题 头文件stdafx.h主要的作用是什么?
database.OpenEx( _T( "DSN=MYDATASOURCE;UID=JOES;PWD=MYPASSWORD" ),
CDatabase::openReadOnly | CDatabase::noOdbcDialog );CString szSQL = "create table ..." ;//会SQL语句就行,
database.ExecuteSQL(szSQL) ;
ID: Q149558
--------------------------------------------------------------------------------
The information in this article applies to:The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.51, 1.52
Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0, 6.0
The Microsoft ODBC Desktop Driver Pack version 2.0
Data Access Pack version 3.5
Microsoft 3.0 ODBC SDK--------------------------------------------------------------------------------
SUMMARY
Prior to the release of the Microsoft ODBC Desktop Driver Pack version 2.0, there was no way to programmatically create a Microsoft Access database (an .mdb file). For more details about this, please see the following article in the Microsoft Knowledge Base: Q118609 HOWTO: Create an .MDB File for Microsoft Access Databases
With the release of the version 2.0 driver pack and higher, MFC ODBC applications can now create .mdb files. Additionally, with the incorporation of DAO into Visual C++ 4.x or higher, you have another way to create Microsoft Access databases programmatically. MORE INFORMATIONUsing the Microsoft Access ODBC Driver to Create .MDB Files
Kyle Geiger's book "Inside ODBC" provides a sample program, ODBCACC, that nicely demonstrates how to use the ODBC installer DLL API function SQLConfigDataSource to create an .mdb file. The syntax of the function call is: BOOL SQLConfigDataSource(hwndParent, fRequest, lpszDriver,
lpszAttributes)
Where:
hwndParent is either NULL if no dialogs are to be displayed or a valid hwnd to act as parent to any driver generated dialogs. fRequest is ODBC_ADD_DSN to specify creation of the .mdb file. lpszDriver is Microsoft Access Driver (*.mdb). lpszAttributes is "CREATE_DB=<path><filename>.mdb <sort order>\0" where the <path><filename> combination identifies where the file should be created and <sort order> is language sorting order (for example, General). <path> must be specified even if the .mdb is to be created in the current working directory. Use standard relative path syntax.
NOTE: Unlike most other ODBC API functions, SQLConfigDataSource returns a boolean value. This return value is TRUE if the .mdb was created, FALSE if creation failed. To use the installer DLL functions, you must:
Use #include <ODBCINST.H>.
Link with Odbcinst.lib for 16-bit applications.
Link with Odbccp32.lib for 32-bit applications.
NOTE: The functionality of SQLConfigDataSource is available through the ODBC Administrator. If you choose to add a new Microsoft Access datasource, the driver dialog includes a Create button that you can use to create an .mdb file interactively.
Using DAO to Create .MDB Files
DAO allows applications developed with Visual C++ 4.x to interface with the Microsoft Jet database engine directly. This allows more efficient manipulation of Microsoft Access objects than can be achieved through ODBC, including the creation of .mdb files. For a sample program that demonstrates how to create databases and other objects, search the Microsoft Knowledge Base for the DAOTABLE sample.
Sample Code
Use of SQLConfigDataSource ODBC installer DLL API function: BOOL fCreated;
fCreated = SQLConfigDataSource(NULL,
ODBC_ADD_DSN,
"Microsoft Access Driver (*.mdb)",
"CREATE_DB=.\\ATest.mdb General\0" );
This will create ATest.mdb in the application's working directory using general sorting. REFERENCES
"Inside ODBC" by Kyle Geiger, Microsoft Press ISBN 1-55615-815-7. For more information, please see the following article in the Microsoft Knowledge Base in the ODBC collection: Q126606 INFO: Accessing CREATE_DB, REPAIR_DB, and COMPACT_DB Additional query words: data base creation creating kbvc151 kbvc152 kbvc200 kbvc210 kbvc220 kbvc400 kbvc500 kbvc600 Keywords : kbprg kbDAO kbDatabase kbMFC kbODBC kbVC kbGrpVCDB
Version : winnt:2.0,2.1,2.2,4.0,4.1,4.2,5.0,6.0
Platform : winnt
Issue type : kbhowto
Technology : kbvc
Last Reviewed: February 16, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.