Page 1 of 1

C++ Builder & UniDAC (Param, ExecSQL)

Posted: Wed 10 Mar 2010 10:17
by asc
Does someone have an example of me, how i set the params in an ExecSQL or ExecSQLEx instruction?

This code doesnt work:

Code: Select all

String value = "Test";
Variant params = VarArrayCreate(OPENARRAY(int,(0,2)), varVariant);
params.PutElement("pValue", 0);
params.PutElement(value , 1);
uniConnection->ExecSQL(
    "INSERT INTO table1 "
    "( Value ) "
    "VALUES "
    "( :pValue ) ",
    &params, 2);

Posted: Thu 11 Mar 2010 14:29
by Falcon
1. Use array creation/initialization code like this:

Code: Select all

Variant* params = new Variant[2];
	params[0] = 1;
	params[1] = 7;
	UniConnection->ExecSQL("INSERT INTO Table (Id, MasterId) VALUES (:pId, :pMasterId)", params, 2);
2. Verify that the number of array elements corresponds to the actual number of parameters in SQL Query.