• delphi连接sql存储过程


    针对返回结果为参数的

    一、 先建立自己的存储过程

    ALTER PROCEDURE [dbo].[REName]
        @Gender    varchar(20)
    AS
    BEGIN
        select ROW_NUMBER() over(order by Name asc) as [序号],
        Name,Gender,Birthday,Mobile,Tel,Ctfld
        from dbo.name
        where Gender = @Gender OR @Gender IN ( NULL, '', '-1' )
    END

    二、打开delphi,先添加几个控件

    ADOConnection1: 连接sql数据库的

    ADOQuery1:连接查询数据的,connection属性设为ADOConnection1

    ADOStoredProc1:连接存储过程的,connection属性设为ADOConnection1,ProcedureName连接存储过程

    DataSource1:Dataset属性设为ADOStoredProc1

    TCombobox:

    TcxButton:查询按钮

    cxGrid1:

    三、设置窗口OnShow事件,把查询的参数添加到TCombobox中

    procedure TForm1.FormShow(Sender: TObject);
    begin
      if adoquery1.Active then adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Text :='select distinct Gender    from dbo.name';
      adoquery1.Open;
      while not adoquery1.Eof do
      begin
        cbbSex.Items.Add(adoquery1.fieldbyname('gender').AsString);
        adoquery1.Next;
      end;
    end;

    四、设置OnDblClick事件,在cxGrid1中显示数据,并在FieldName中选择参数

    procedure TForm1.cxGrid1DBTableView1DblClick(Sender: TObject);
    begin
      try
        screen.Cursor :=crhourglass;
        adostoredproc1.Close;
        adostoredproc1.Parameters.ParamByName('@Gender').Value :=(cbbSex.Text);
        adostoredproc1.Open;
      finally
        screen.Cursor :=crdefault;
      end;
    end;

    五、查询事件

    procedure TForm1.cxButton1Click(Sender: TObject);
    begin
      try
      adostoredproc1.Close;
      begin
        adostoredproc1.Parameters.ParamByName('@Gender').Value :=trim(cbbSex.Text);
        adostoredproc1.Open
      end;
      finally
        screen.Cursor :=crdefault
      end;
    end;

    刚学的,顺便整理思路

  • 相关阅读:
    win7 安装 redis +php扩展
    HTTP Status 500
    浅谈java8新特性之stream
    关于排序算法中的稳定与不稳定
    关于面试中的mysql试题1
    mysql关于case-when-end的使用
    eclipse项目启动报:Project facet Java version 1.8 is not supported
    mysql 5.7密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    浅谈并行与并发
    浅谈Java垃圾回收(GC)
  • 原文地址:https://www.cnblogs.com/Michael-D/p/4278621.html
Copyright © 2020-2023  润新知