Using ParseSQL Command for ADO Parameters Cause Invalid Parameter DataType

自作多情 提交于 2019-12-04 17:33:12
Mohammad Gohari

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!