Thursday, June 14, 2007

Using TADO Objects

This was a major pain in the neck. The documentation in Borland is not clear; however, I now have something working.

I should mention that I am working with Access 2003 and Borland Builder 6.0 Professional.

For my experience so far I believe the following to be true:
  • There is no way to setup an ADO connection in ODBC (I could be wrong in this but it is not clearly obvious how one would set it up.)
  • Procedures can be created and destroyed. In TQuery they can only be created.
I was able to get the connection string using the Borland ADO controls. The is a helper for building the string and I don't think I could have done what I did without it.

The following test code compiled and ran and worked.

#include

TADOConnection *conn = new TADOConnection( NULL );

conn->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=C:\\LU_IncomingQC_APB.mdb;"
"Persist Security Info=False" ;
conn->Open();
TADOQuery *qry = new TADOQuery( NULL );
qry->Connection = conn;

// Create the procedure to be called
sql = "CREATE PROC createTable "
" (NewTable TEXT) AS "
" CREATE TABLE NewTable "
" ( "
" InvoiceID INTEGER NOT NULL, "
" InvoiceDate DATETIME NOT NULL "
" ); ";

sql = "CREATE PROCEDURE DeleteInvoices AS (DROP TABLE testTable1)";
qry->SQL->Clear();
qry->SQL->Add( sql );
qry->ExecSQL();

sql = "DROP PROC DeleteInvoices;";

qry->SQL->Clear();
qry->SQL->Add( sql );
qry->ExecSQL();

normal

No comments: