ClientDataSet1.CommandText := sSQL; ClientDataSet1.Params.Clear; ClientDataSet1.CommandText :='SELECT * FROM test WHERE ID=:TID and Code=:Code '; //传参后面加一个空格 ClientDataSet1.Params.ParamByName('TID').AsInteger:=1001; ClientDataSet1.Params.ParamByName('Code').AsString:= '5668';
//每个":Code "后面,都跟上一个“ ”(空格)
function TWorkWindowForm.GetDataSetSQL(DataSet: TClientDataSet): string; var i:integer; sSQL, sName, sVaule:string; begin Result := ''; DataSet.Close; sSQL := DataSet.CommandText; for i:=0 to DataSet.Params.Count-1 do begin sName := DataSet.Params.Items[i].Name; sVaule := DataSet.Params.Items[i].Value; if DataSet.Params.Items[i].DataType in [ftString,ftMemo] then //根据数据类型 自己再修改一下 sSQL:=StringReplace(sSQL, ':'+sName+' ' , QuotedStr(sVaule)+' ',[rfReplaceAll]) else sSQL:=StringReplace(sSQL, ':'+sName+' ' ,sVaule+' ' ,[rfReplaceAll]); end; Result := sSQL; end;
|
请发表评论