使用ParseSQL命令进行ADO参数导致参数DataType无效

时间:2022-10-29 11:10:23

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

我有一些SQL命令包含一个参数:(注意myID在SQL中有“int”类型)

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

vSqlString:='Select * from myTable where myID =:paramID';

and Use ParseSQL Command to execute this command:

并使用ParseSQL命令执行此命令:

myADOQuery.Parameters.ParseSQL(vSqlString , True);

myADOQuery.Parameters.ParseSQL(vSqlString,True);

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

现在myADOQuery.Parameters.ParamByName('paramID')。DataType是smallint Type,它不能接受负整数值。

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?

我可以准确地向编译器显示我的Parameter [0] .DataType是ftIneteger并且它正常工作,但是对于这个问题有什么好的解决方案?

2 个解决方案

#1


2  

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

imanShadabi先生问我的问题:使用TAdoQuery.ParseSql并通过user1008646解决

#2


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


2  

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

imanShadabi先生问我的问题:使用TAdoQuery.ParseSql并通过user1008646解决

#2


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.

第三种选择是在设计时设置参数。但我认为这不是你想要的。