ADO - Using CommandPtr

ADO - Using CommandPtr

Post by Anders Eri » Fri, 20 Feb 2004 00:13:50


Hello!

I have some questions about using a CommandPtr to execute an SQL statement
in an Access 97 database.

The SQL statement is:
"INSERT INTO APPLICATION
(NAME,DESKVA,DESKMAP,KEY,XDATA,KEYCOLUMN,KEYTYPE,PUNKT,mstrPID1066,PIDNUM,LEDNING,mstrLID1066,LIDNUM,SELECTED,RESULT)
VALUES ('xx',1,0,'MSTRKEY',1,'1',1,'','',0,'','',0,'','')"

I have a correct database with the table and the table have all columns.

I create a CommandPtr using a active connection:

pCommand = NULL;
pCommand.CreateInstance(__uuidof(Command));
pCommand->CommandText = _bstr_t(strCommandText); //.AllocSysString();
pCommand->CommandType = adCmdText;
pCommand->ActiveConnection = pAdoDatabase->GetActiveConnection();


I then call Execute()

_variant_t vRecords;
pCommand->Execute(&vRecords, NULL, adCmdText);

I then get an Exception saying: "Syntax error in INSERT INTO statement"

If I copy the SQL statement and creates a Query and then run the query then
everything works.

1:st Question: Can anyone figure out why I get the error message?

2:nd Question: Do I need to set the third param in the Execute() when I
already have set pCommand->CommandType??

// Anders
 
 
 

ADO - Using CommandPtr

Post by Anders Eri » Fri, 20 Feb 2004 20:53:13


OK, I found the error! As usual it was mine ;-)

I have a column called KEY, which is a reserved word in Jet SQL.

The strange thing is that this SQL statement has worked via DAO in over 10
years!!

Well I have now changed the column name to XKEY and now everything is
working!!!

// Anders