저장 프로세스 호출 [Delphi 버전]

10454 단어 Delphi
A) 매개변수로 반환
 
var
 
Cn:TAdoConnection;
 
Sp:TAdoStoredProc;
 
recordCount:
string
;
 
 
begin
 
Cn :
=
TAdoConnection.Create(
nil
);
 
try
Cn.ConnectionString :
=
[데이터베이스 연결 문자열];
Cn.LoginPrompt :
=
False;
Cn.KeepConnection :
=
True;
Cn.ConnectionTimeout:
=
2
;
try
Cn.Open;
Sp :
=
TAdoStoredProc.Create(
nil
);
try
Sp.Connection :
=
Cn;
Sp.Close;
Sp.ProcedureName :
=
'
getStudentAmount
'
;
Sp.Parameters.Refresh;
//
매개 변수의 초기화는refresh 다음에 두어야 한다
Sp.Parameters.ParamByName(
'
@recordCount
'
).Value:
=
0
;
//
저장 과정 중의 모든 매개 변수는
Sp.ExecProc;
//
반환 매개변수를 포함한 초기화
recordCount:
=
inttostr(Sp.Parameters.ParamByName(
'
@recordCount
'
).Value);
finally
Sp.Free;
end
;
except
on E:EoleException
do
begin
ShowMessage(
'
데이터베이스 연결이 실패했습니다. 연결을 확인하십시오.
'
);
end
;
end
;
finally
Cn.Free;
end
;
 
end
;
B) 데이터 세트로 반환
1) 단일 데이터 세트
var
Cn:TAdoConnection;
Sp:TAdoStoredProc;
nameFieldString:string;
begin
Cn := TAdoConnection.Create(nil);
Sp := TAdoStoredProc.Create(nil);
try
Cn.ConnectionString := [ ];
Cn.LoginPrompt := False;
Cn.KeepConnection := True;
Cn.ConnectionTimeout:=2;
try
Cn.Open;
Sp.Connection := Cn;
Sp.Close;
Sp.ProcedureName :='queryAllStudentInfo';
Sp.Parameters.Refresh;
Sp.Active:=True;// , , “ ”
Sp.open;// ExecProc, Open, Open
whilenot Sp.Eof do
begin
nameFieldString:=Sp.FieldByName('SName').AsString;
nameFieldString:=Trim(nameFieldString);
Sp.Next;
end;
except
on E:EoleException do
begin
ShowMessage(' , ');
end;
end;
finally
Sp.Free;
Cn.Free;
end;
end

2) 다중 데이터 세트
var
Cn:TAdoConnection;
Sp:TAdoStoredProc;
AdoQuery:TAdoQuery;
nameFieldString:
string;

aintf:_Recordset;
RecordsAffected:OleVariant;
begin
Cn :
= TAdoConnection.Create(nil);
try
Cn.ConnectionString :
=MainForm.DatabaseConnStr;
Cn.LoginPrompt :
= False;
Cn.KeepConnection :
= True;
Cn.ConnectionTimeout:
=2;
try
Cn.Open;
Sp :
= TAdoStoredProc.Create(nil);
AdoQuery:
=TAdoQuery.Create(nil);
try
Sp.Connection :
= Cn;
Sp.Close;
Sp.ProcedureName :
='CIB_GetCheckAccountFileInfo';
Sp.Active:
=True;//
Sp.Parameters.Refresh;

           Sp.Active:
=True;// , , “ ”

Sp.open;
// ExecProc, Open, Open

aintf:
=Sp.Recordset;
AdoQuery.Recordset:
=aintf;
whilenot AdoQuery.Eof do
begin
nameFieldString:
=AdoQuery.FieldByName(' ').AsString;
nameFieldString:
=Trim(nameFieldString);
showmessage(
''+nameFieldString);
AdoQuery.Next;
end;

aintf:
=aintf.NextRecordset(RecordsAffected);
AdoQuery.Recordset:
=aintf;
whilenot AdoQuery.EOF do
begin
nameFieldString:
=AdoQuery.FieldByName(' ').AsString;
nameFieldString:
=Trim(nameFieldString);
showmessage(
''+nameFieldString);
AdoQuery.Next;
end;
finally
AdoQuery.Free;
Sp.Free;
end;
except
on E:EoleException
do
begin
ShowMessage(
' , ');
end;
end;
finally
Cn.Free;
end;
end;

 
 
 

좋은 웹페이지 즐겨찾기