如何在C ++中使用ADO获取MS Access数据库表的上次修改日期/时间
问题描述:
大家好,
谁能告诉我如何通过使用VC ++和ADO数据库编程来获取MS Access数据库文件(* .MDB文件)表的最后修改日期和时间.
实际上,我的目标是根据表的最后修改时间将表导出为XML.
请尽快提供解决方案.
谢谢.
Hello Guys,
Can anybody tell me How to get last modified Date and time of tables of MS Access database file (*.MDB file) by using VC++ with ADO database programming.
Actually, My objective is to export the tables to XML on the basis of last modified time of table.
Please provide the solution ASAP.
Thank You.
答
以下程序列出了访问数据库中所有表的最后修改日期.在这里,您以字符串(_bstr_t)类型检索日期.您需要将其转换为某些c ++ date类型的数据类型,以进行比较并在其中找到最新的数据类型.您需要编写自己的逻辑
following program list the date last modified for all tables in an access database. Here you are retrieving date as string(_bstr_t) type. You need to convert it to some of c++ date kind of data type to compare and find the latest among it. That logic you need to write yourself
#include <stdio.h>
#include <ole2.h>
#include <oleauto.h>
#import " C:/Program Files/Common Files/System/ado/msado15.dll" rename( "EOF", "AdoNSEOF" )
_bstr_t bstrConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= D:\\TestDB.accdb;";
using namespace std;
using namespace ADODB;
int main()
{
if ( FAILED(::CoInitialize(NULL)) )
return -1;
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstSchema = NULL;
_bstr_t strCnn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\MyTrainingDB\\Training.accdb;";
try {
// Open connection.
pConnection.CreateInstance(__uuidof(Connection));
pConnection->Open (strCnn, "", "", adConnectUnspecified);
pRstSchema = pConnection->OpenSchema(adSchemaTables);
while ( !(pRstSchema->AdoNSEOF) )
{
_bstr_t table_type = pRstSchema->Fields->GetItem("TABLE_TYPE")->Value;
LPCSTR lpcszType = (LPCSTR) table_type;
LPCSTR lpcszTable = "TABLE";
if( 0 == strcmp( lpcszType, lpcszTable ))
{
_bstr_t table_name = pRstSchema->Fields->GetItem("TABLE_NAME")->Value;
printf("Table Name: %s\n",(LPCSTR) table_name);
_bstr_t table_date = pRstSchema->Fields->GetItem("DATE_MODIFIED")->Value;
printf("Table Modified Time: %s\n\n",(LPCSTR) table_date);
}
pRstSchema->MoveNext();
}
}
catch (_com_error &e)
{
// Handle Exception
}
// Clean up objects before exit.
if (pRstSchema)
if (pRstSchema->State == adStateOpen)
pRstSchema->Close();
if (pConnection)
if (pConnection->State == adStateOpen)
pConnection->Close();
::CoUninitialize();
getchar();
}