2个回答
2013-06-08
展开全部
ADODataSet.Close;
ADODataSet.CommandText:= "Select * from Test where Code=:Code ";
ADODataSet.Parameters.Clear;
ADODataSet.Parameters.ParseSQL(ADODataSet.CommandText,true); ADODataSet.Parameters.ParamByName( "Code ").Value := '001 ';
ADODataSet.Open;以上代码中,语句 ADODataSet1.Parameters.ParseSQL(ADODataSet.CommandText, true) 是关键代码。通过 ParseSQL 方法解构 ADODataSet.CommandText 的 SQL 语句,建立 ADODataSet1 新的对象参数,从而使新的查询生效。 附:Delphi 文档中对 ParseSQL 方法的描述: ParseSQL method (TParameters): Parses an SQL statement for parameters and TParameter objects. Delphi syntax: function ParseSQL(SQL: String; DoCreate: Boolean): String; Description Call ParseSQL to parse an SQL statement for parameters. For each parameter found in the SQL statement, a TParameter object is added to the calling TParameters object using the name of the parameter in the SQL statement. SQL contains the SQL statement to parse. DoCreate indicates whether to clear all existing parameter definitions before parsing the SQL statement. ParseSQL returns a parsed version of the SQL statement specified in the SQL parameter. ADOQuery1.Parameters.ParseSQL(ADOQuery1.Text, True);
ADODataSet.CommandText:= "Select * from Test where Code=:Code ";
ADODataSet.Parameters.Clear;
ADODataSet.Parameters.ParseSQL(ADODataSet.CommandText,true); ADODataSet.Parameters.ParamByName( "Code ").Value := '001 ';
ADODataSet.Open;以上代码中,语句 ADODataSet1.Parameters.ParseSQL(ADODataSet.CommandText, true) 是关键代码。通过 ParseSQL 方法解构 ADODataSet.CommandText 的 SQL 语句,建立 ADODataSet1 新的对象参数,从而使新的查询生效。 附:Delphi 文档中对 ParseSQL 方法的描述: ParseSQL method (TParameters): Parses an SQL statement for parameters and TParameter objects. Delphi syntax: function ParseSQL(SQL: String; DoCreate: Boolean): String; Description Call ParseSQL to parse an SQL statement for parameters. For each parameter found in the SQL statement, a TParameter object is added to the calling TParameters object using the name of the parameter in the SQL statement. SQL contains the SQL statement to parse. DoCreate indicates whether to clear all existing parameter definitions before parsing the SQL statement. ParseSQL returns a parsed version of the SQL statement specified in the SQL parameter. ADOQuery1.Parameters.ParseSQL(ADOQuery1.Text, True);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询