Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters to ADOCommand for SQL INSERT

Status
Not open for further replies.

marflo500

IS-IT--Management
May 16, 2007
36
DM
HEllo All,

I am trying to insert records into a database using an ADOCommand component but I seem to be having a few problems. I have created all the insert parameters using the Object Inspector but I have chosen to assign the CommandText (SQL INSERT statement) at runtime as well as the values of the parameters. I have left ParamCheck as FALSE in the Object inspector. In the CommandText Property I referenced the parameters using the ':param' syntax as shown below. However, when the command is executed I get an Access Violation Error. Is there something I am missing?


Parameters[0].Value := StrToFloat(ParamArray[0]);
Parameters[1].Value := StrToFloat(ParamArray[1]);
Parameters[2].Value := ParamArray[2];
Parameters[3].Value := ParamArray[3];
Parameters[4].Value := StrToInt(ParamArray[4]);
Parameters[5].Value := StrToInt(ParamArray[5]);
Parameters[6].Value := ParamArray[6];
Parameters[7].Value := StrToInt(ParamArray[7]);
Parameters[8].Value := StrToFloat(ParamArray[8]);
Parameters[9].Value := ParamArray[9];
Parameters[10].Value :=ParamArray[10];
Parameters[11].Value := StrToFloat(ParamArray[11]);
Parameters[12].Value := StrToInt(ParamArray[12]);
Parameters[13].Value := StrToInt(ParamArray[13]);
Parameters[14].Value := StrToFloat(ParamArray[14]);
Parameters[15].Value := StrToFloat(ParamArray[15]);
Parameters[16].Value := StrToFloat(ParamArray[16]);

CommandText := 'INSERT INTO ARIBH (CNTBTCH,CNTITEM,IDCUST,IDINVC,TEXTTRX,'
+'IDTRX,INVCDESC,SWPRTINVC,DATEINVC, CODECURN,TERMCODE,'
+'DATEDUE,SWTAXBL,TAXSTTS1,BASETAX1,AMTTXBL,AMTINVCTOT) '
+'VALUES :)@CNTBTCH,:mad:CNTITEM,:mad:IDCUST,:mad:IDINVC,:mad:TEXTTRX,'
+':mad:IDTRX,:mad:INVCDESC,:mad:SWPRTINVC,:mad:DATEINVC, :mad:CODECURN,:mad:TERMCODE,'
+':mad:DATEDUE,:mad:SWTAXBL,:mad:TAXSTTS1,:mad:BASETAX1,:mad:AMTTXBL,:mad:AMTINVCTOT)';


Thanks
Liam
 
I don't use Parameters that often because of these sorts of reliability issues.

Is there any reason you're using the @ symbols in your SQL? I'd try removing them.

It could be that the Parameters property is not being properly created. As a test, use the AddParameter method to create your parameters in your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top