with (TStoredProc.Create(nil))do begin try DatabaseName := 'DBName'; StoredProcName := 'ProcName'; Params.CreateParam(ftString,'@Param',ptInput);
Params.ParamByName('@Param').AsString := '123';
Prepare; Active := True; if RecordCount<>0 then ParamByName('@Param').AsString; //返回值 finally if Active then active:=False; Free; end;//try
with TStoredProc.Create(nil) do begin try DatabaseName := 'PdyuDB'; StoredProcName := 'GetAll'; Params.CreateParam(ftInteger, '@ID', ptInput); Params.ParamByName('@ID').AsInteger := 1; Prepare; Active := True; if RecordCount <> 0 then begin while not Eof do begin nID := FieldByName('ProductID').AsInteger;//返回数据集的字段 strName := FieldByName('ProductName').AsString; nPrice := FieldByName('Price').AsInteger; Next; end; end; finally if Active then Active := False; Free; end;
(
@count int output
)
as
select @count=count(*) from table_name;
使用StoredProc,可以得到所有的返回信息吗?我说的返回信息有很多条记录!
begin
try
DatabaseName := 'DBName';
StoredProcName := 'ProcName'; Params.CreateParam(ftString,'@Param',ptInput);
Params.ParamByName('@Param').AsString := '123';
Prepare;
Active := True;
if RecordCount<>0 then
ParamByName('@Param').AsString; //返回值
finally
if Active then active:=False;
Free;
end;//try
begin
try
DatabaseName := 'PdyuDB';
StoredProcName := 'GetAll'; Params.CreateParam(ftInteger, '@ID', ptInput);
Params.ParamByName('@ID').AsInteger := 1; Prepare;
Active := True;
if RecordCount <> 0 then
begin
while not Eof do
begin
nID := FieldByName('ProductID').AsInteger;//返回数据集的字段
strName := FieldByName('ProductName').AsString;
nPrice := FieldByName('Price').AsInteger;
Next;
end;
end;
finally
if Active then Active := False;
Free;
end;