Hi, I have a problem with TMSQuery
Example:
CREATE TABLE Test (
ID int NOT NULL PRIMARY KEY,
Data varchar
)
Query.SQL.Text := 'SELECT * FROM Test WHERE ID=:ID and Data=:Data';
Query.Prepare;
//OK
Query.SQL.Text := 'INSERT INTO Test(ID, Data) VALUES(:ID, :Data)';
Query.Prepare;
//ERROR
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EMSError with message 'Statement(s) could not be prepared.
Implicit conversion from data type sql_variant to int is not allowed. Use the CONVERT function to run this query.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
How do I properly prepare the INSERT, without having to explicitly define the parameters?
Thanks for the reply.
Query.Prepare - Statement(s) could not be prepared.
-
- Posts: 20
- Joined: Fri 29 Jan 2010 10:05
- Contact:
To solve the problem you should specify parameters data type before calling the Prepare method, like this:
Code: Select all
Query.ParamByName('ID').DataType := ftInteger;
Query.ParamByName('Data').DataType := ftString;
Query.Prepare;
-
- Posts: 20
- Joined: Fri 29 Jan 2010 10:05
- Contact:
TMSQuery.Prepare
Ok set parameters before the command PREPARE. Thank you for your response.
Extends great application for support MSSQL. In třiídě Query to Firebird to Oracle PREPARE can create parameters from the query.
Is there any way to get through TMSQuery parameters automatically from TMSQuery.SQL.Text with defined types?
Thank you for your answer.
Extends great application for support MSSQL. In třiídě Query to Firebird to Oracle PREPARE can create parameters from the query.
Is there any way to get through TMSQuery parameters automatically from TMSQuery.SQL.Text with defined types?
Thank you for your answer.