2

I have some SQL Command that contains a parameter such:(Note that myID has "int" type in SQL)

vSqlString :='Select * From myTable Where myID= :paramID';

and Use ParseSQL Command to execute this command:

myADOQuery.Parameters.ParseSQL(vSqlString , True);

Now myADOQuery.Parameters.ParamByName('paramID').DataType is smallint Type and it can't accept negative integer values.

I can exactly show to compiler that my Parameter[0].DataType is ftIneteger and it works properly, but what is a good solution for this problem?

9
  • Have you tried changing the datatype: myADOQuery.Parameters.ParamByName('paramID').DataType := ftInteger; Commented Dec 28, 2013 at 10:59
  • Alternatively you can set up the parameters manually rather than by calling ParseSQL. Commented Dec 28, 2013 at 11:00
  • 1
    what is your DB backend? Smallint type is rather weird for an identity column? Commented Dec 28, 2013 at 11:17
  • 4
    @MohammadGohari I think that is the best solution. The compiler cannot query the DB to see what the column datatypes are so you have to tell it. Personally I don't use ParseSQL, I set up the parameters in code so I have full control. Commented Dec 29, 2013 at 9:36
  • 2
    see this article [ADOQuery.ParseSql][1] [1]: stackoverflow.com/questions/21194122/… Commented Jan 21, 2014 at 5:47

2 Answers 2

3
+50

My question is asked by Mr. imanShadabi Here: Using TAdoQuery.ParseSql and has resolved by user1008646

Sign up to request clarification or add additional context in comments.

2 Comments

Glad I could help. I wonder how I'd go about collecting the bounty.
@user1008646, don't worry. You'll get one :-)
0

Hope this will help.

If you want to create in runtime parameters, you can use something like this:

ADOQuery1.Close;
ADOQuery1.SQL.Text := vSqlString;
ADOQuery1.Parameters.Clear;
ADOQuery1.Parameters.CreateParameter('paramID', ftInteger, pdInput, 10, vIntegerValue);
ADOQuery1.Open;

Or you can concatenate values to the query. For example:

//For Integer values:
vSqlString: = 'Select * From myTable Where myID =' + IntToStr (vIntegerValue); 

//For String values:
vSqlString: = 'Select * From myTable Where myID =' + QuotedStr (vStringValue); 

//For float values: 
//Be careful with this, usually in a query, the comma is separator values, 
//so make sure that the decimal separator is '.'
vDS := DecimalSeparator; //I keep the value it had 
DecimalSeparator := '.'; 
try
  ADOQuery1.close;
  ADOQuery1.SQL.Text := 'Select * From myTable Where myID='+FloatToStr(vFloatValue);
  ADOQuery1.Open;
finally
  DecimalSeparator := vDS; //Restore the value that had
end;

The third option is to set the parameters at design time. But I think this is not what you want.

1 Comment

thanks aljarafe. but I wanna use ParseSQL and know this command bug

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.