Hi,
As per my point of view to access the database outside of AX DB using the CCADO classes method is more effective than using the LoginProperty class.
Below is the use of CCADO classes:
Basically there are 3 main classes:
1. CCADOConnection
2. CCADORecordSet
3. CCADOCommand
Below is the source code template to use the CCADO classes in AX:
X++:
static void Tutorial_CCADO (Args _args)
{
CCADOConnection Connection; CCADOConnection Connection;
SQL str;
CCADORecordSet RSet;
CCADOCommand ADOCom;
;
CCADOConnection = new Connection ();
Connection. ConnectionString (StrFmt ("Provider = SQLOLEDB.1; Persist Security Info = False; User ID =% 3;Password =% 4; Initial Catalog =% 2; Data Source =% 1, '192 .162.0.100','TestBBDD','Sa','sa'));
//Open the connection
Connection.Open ();
CCADORecordSet Rset = new ();
// The decision to execute
SQL = 'Select * from CustTable';
// Execute the query using the previously opened connection
RSET.Open(SQL, Connection);
// Loop while there are records
While(!RSET.EOF())
(
// Display the field AccountNum
info(RSet.fields().itemName('Accountnum').value());
// Next Record
RSet.moveNext();
)
// Now ADOCommand
ADOCom = new CCADOCommand();
// Open connection I associate
ADOCom.activeConnection(Connection);
// Prepare a SQL data modification
SQL = "delete CustTable where AccountNum = '%1'";
// Execute the sentence - in theory delete the record 'cli0001'
ADOCom.commandText(StrFmt( SQL, 'cli0001'));
ADOCom.Execute();
}
Thanks,
Ashlesh
No comments:
Post a Comment