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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TADOCommand Parameters referencing field names with spaces 1

Status
Not open for further replies.

Errol99

Programmer
Jan 6, 2010
2
NZ
thread102-747014
I wish to parameterise a TADOCommand on a table with spaces in the field names (e.g. 'Well Test Type'). For a SQL Server query I have used the following CommandText:
INSERT INTO table "Well Test Type" VALUES :)"Well Test Type");

However, when I try to get a value for the field using:
Parameters.ParamByName('Well Test Type').Value := SomeValue;

I get the following error:
ADOCommand: Parameter 'Well Test Type' not found.

Everything works fine if no spaces in the field name. I have tried a range of delimiters but no success to date. Any ideas?
 
Your parameter doesn't have to have the spaces. SQL can use double quotes or square brackets:

INSERT INTO TABLE [Well Test Type] VALUES :)WellTestType);

Parameters.ParamByName('WellTestType').Value := SomeValue;

That being said I use code like this:
Code:
  with ADOStoredProc do
  begin
    ProcedureName := 'InsertDS_JOURNAL_AUDIT';
    Parameters.Refresh;
    Parameters.ParamByName('@CHART_CODE').Value := aChartCode;
    Parameters.ParamByName('@THE_DATEI').Value := aTheDateI;
    Parameters.ParamByName('@ACTION_ID').Value := aActionID;
    Parameters.ParamByName('@AUDIT_DATETIME').Value := aTimestamp;
    Parameters.ParamByName('@USER_ID').Value := aUserID;
    Parameters.ParamByName('@DESCRIPTION').Value := aDescription;
    ExecProc;
  end;
 
Thanks. I realised this was the solution as I lay awake mulling it over at 4 am. However, as I derive the parameters from the field names, I will need to use a StringReplace function to remove the spaces.
 
IMHO, the spaces should have never been there...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top