I have to execute multiple INSERT
queries and I wish to reuse one Command
object instead to make new one for every query I have.
To illustrate this better here is a pseudo-code :
ADODB::_CommandPtr pCmd("ADODB.Command");
pCmd->ActiveConnection = pConn;
pCmd->CommandText = L"INSERT INTO MyTable ( field1, field2 ) VALUES (?,?);";
pCmd->Parameters->Append( pCmd->CreateParameter( "?", ADODB::adVarWChar,
ADODB::adParamInput, wcslen( myString ), myString ) );
pCmd->Parameters->Append( pCmd->CreateParameter( "?", ADODB::adDouble,
ADODB::adParamInput, sizeof(double),
_wtof_l( myDouble, _get_current_locale() ) ) );
pCmd->Execute( NULL, NULL, ADODB::adCmdText );
// empty parameters collection->the problematic part
/**** execute second query **************/
pCmd->CommandText = //some other query
// and do basically the same as above:
// append some parameters and execute query
I do not know how to delete all parameters from Parameters
collection so I can reuse the Command
object for another SQL
query.
Being inexperienced, I have tried finding the solution on the internet and found some suggestions on how to do it. Here are my tries:
do
{
pCmd->Parameters->Delete(0);
}
while( pCmd->Parameters->GetCount() > 0 );
but failed. I have also tried this:
for( long i = 0; i < pCmd->Parameters->GetCount(); i++ )
pCmd->Parameters->Delete(i);
but that failed too.
How can I empty Parameters
collection properly so I can reuse the Command
object?
Thank you.
Best regards.