Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

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
C++
#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();
}
 
Share this answer
 
v2
Comments
saqib.akhter 3-Apr-12 8:58am    
Thanks a lot.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900