zoukankan      html  css  js  c++  java
  • 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;

    刚学的,顺便整理思路

  • 相关阅读:
    服务器搭建FTP
    VS2012 +OpenCv2.4.4配置
    python3:语法变动 及新特性
    Strlen()与sizeof()
    find命令下的atime,ctime,mtime
    C语言实现线性表
    去除zabbix calculate 模式下,有时候分母为零的情况(Cannot evaluate expression: division by zero. )
    C语言面试题汇总之一
    全局变量/静态全局变量/局部变量/静态局部变量的异同点
    MFC的自定义消息的定义与使用
  • 原文地址:https://www.cnblogs.com/Michael-D/p/4278621.html
Copyright © 2011-2022 走看看