delphi存储过程(返回值)

unit K_ProcManage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;

type
  TProcManage = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    MyStoredProc: TADOStoredProc;
    Button2: TButton;
    ADOQuery1: TADOQuery;
    ADOStoredProc1: TADOStoredProc;
    Edit6: TEdit;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ProcManage: TProcManage;

implementation
   uses D_DataMoudule;
{$R *.dfm}


procedure TProcManage.Button1Click(Sender: TObject);
var
  i:integer;
begin
with MyStoredProc do
begin
  ProcedureName:='InsertStud';
  Parameters.Clear;
  Parameters.CreateParameter('@StudID', ftString, pdInput, 50, edit1.Text);
  Parameters.CreateParameter('@StudName', ftString, pdInput, 50, edit2.Text);
  Parameters.CreateParameter('@Sex', ftString, pdInput, 50, edit3.Text);
  Parameters.CreateParameter('@Age', ftString, pdInput, 50, edit4.Text);
  Parameters.CreateParameter('@Telephone', ftString, pdInput, 50, edit5.Text);
  Parameters.CreateParameter('@returnValue', ftInteger, pdOutput, 10, 0);
  Prepared:= true;
  ExecProc;
  i:=Parameters.ParamByName('@returnValue').value;
  edit6.Text:=inttostr(i);
end;
end;



procedure TProcManage.Button2Click(Sender: TObject);
var
  SQLProc:string;
  i:integer; //声明变量来测试返回值的成功

begin
    adoquery1.SQL.Clear;
    SQLProc:='exec InsertStud '''+edit1.Text+''','''+edit2.Text+''','''+edit3.Text+''','''+edit4.Text+''','''+edit5.Text+''',:C output';
    adoquery1.SQL.Add(SQLProc);
    adoquery1.ExecSQL;
    i:=adoquery1.parameters.Items[0].Value;               //2对应着C,为返回值赋值
    edit6.Text:=inttostr(i);


    //其它
    
end;

procedure TProcManage.Button3Click(Sender: TObject);
var
  SQLProc:string;
  i:integer; //声明变量来测试返回值的成功

begin
   adoquery1.SQL.Clear;
   SQLProc:='exec InsertStud :A,:B,:C,:D,:E,:F output';
   adoquery1.SQL.Add(SQLProc);
   adoquery1.Parameters.Items[0].Value:=edit1.Text;
   adoquery1.Parameters.Items[1].Value:=edit2.Text;
   adoquery1.Parameters.Items[2].Value:=edit3.Text;
   adoquery1.Parameters.Items[3].Value:=edit4.Text;
   adoquery1.Parameters.Items[4].Value:=edit5.Text;
   adoquery1.Prepared;
   adoquery1.ExecSQL;
   i:=adoquery1.Parameters.Items[5].Value;
   edit6.Text:=inttostr(i);

end;

end.


阅读更多
个人分类: Delphi
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭