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

Parameter types against queries with dynamic SQL syntax

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I have an application written in Delphi 5 that uses query components working against a SQL server 7.0 database. If I have queries with hard-coded SQL syntax (i.e. 'SELECT [FirstName], [Surname] FROM [Users] WHERE [UserID] =:pUserID) then I can set the parameter types (in this case the parameter 'pUserID' can have 'Integer' set as the parameter type). If I am dynamically setting the SQL syntax for the query components at run-time (according to the tables I want to retrieve data from) how do I set the data-types for the parameters. If I do not set the parameter types and try to activate one of these queries and attempt to clear one of the parameters (using 'Query1.Params[1].Clear') I get an error message indicating that the parameter type is not known and the application halts.
The only way round this (found through much trial and error) was to have a line of code 'Query1.Params[1].AsInteger := 0' before the clearing of parameter. This then tells the program that the parameter is of type 'Integer' and then allows us to clear the parameter type.
Is this the best way to handle this issue - or is there a better method ?
Thanks in advance.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top