How to create mdb dynamic(vc6.0+ado)?

来源:互联网 发布:杰普软件 编辑:程序博客网 时间:2024/05/22 03:11

In csdn bbs, I found there was a lot of programmer to ask how to   create mdb dynamic?

Now I give my resolvent!

here is the main code(vc6.0+ado):

 

#import "c:/Program Files/Common Files/system/ado/msadox.dll" rename_namespace("ADOX") #import "c:/Program Files/Common Files/System/ADO/msado15.dll" / rename_namespace("ADO") rename("EOF", "EndOfFile")#pragma warning (disable: 4146)#include "icrsint.h"#include "Shlwapi.h"#pragma comment(lib,"Shlwapi.lib")using namespace ADO;CoInitialize(NULL);using namespace ADOX;_CatalogPtr m_pCatalog = NULL;CString strConnection, strTable;TCHAR chFilePath[MAX_PATH];GetModuleFileName(NULL,chFilePath,MAX_PATH);(_tcsrchr(chFilePath, '//'))[1] = 0;lstrcat(chFilePath , _T("Test.mdb"));strTable = chFilePath;strConnection = _T("Provider=Microsoft.JET.OLEDB.4.0;Data source = ") + strTable + _T(";Jet OLEDB:Engine Type=5;");if(!PathFileExists(chFilePath)){  try  {    m_pCatalog.CreateInstance(__uuidof(Catalog));    m_pCatalog->Create(_bstr_t(strConnection ));  }  catch(...)  {    m_pCatalog->Release();    m_pCatalog = NULL;    CoUninitialize();  }  m_pCatalog->Release();  // m_pCatalog->Release();  // m_pCatalog = NULL;}CoUninitialize();
if there is some errors,please email to me :  monkeycd@163.com  :)
 

operating system:winxp+vc6.0+vsp6.0+access2000

原创粉丝点击