您的位置:首页 > 编程语言 > Delphi

Delphi实现数据库查询编辑功能

2017-01-03 09:51 387 查看
在开始之前我们先看下功能

运行时:






点击搜索:






点击编辑:






步骤如下:

首先要有安装UniDAC控件(具体安装方式参考UniDAC的安装和使用博文)

然后在Form添加几个控件:TUniDataSource,TUniConnection,TMySQLUniProvider,TUniQuery,TDBText,TDBEdit,TDBMemo,TDBGrid,TButton,TButton

接着设置:

UniConnection1,双击UniConnection1选项Connect设置相关参数和Options的UseUnicode设置为True(这样中文会正常显示)

UniQuery1设置Connection选择UniConnection1,双击UniQuery1输入SQL语句select * from tablename


UniDataSource1设置DataSet选择UniQuery1

最后代码如下:

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, Grids, DBGrids, UniProvider, MySQLUniProvider, DB, DBAccess,

  Uni, MemDS, StdCtrls, Mask, DBCtrls, jpeg, ExtCtrls;

type

   TForm1 = class(TForm)

    UniConnection1: TUniConnection;

    UniQuery1: TUniQuery;

    UniDataSource1: TUniDataSource;

    MySQLUniProvider1: TMySQLUniProvider;

    Button1: TButton;

    DBEdit1: TDBEdit;

    DBText1: TDBText;

    DBMemo1: TDBMemo;

    DBGrid1: TDBGrid;

    Button2: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

 begin

 UniQuery1.Active:=True;

 end;

procedure TForm1.Button2Click(Sender: TObject);

begin

     UniDataSource1.DataSet.Post;

     showmessage('修改成功!');

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

end;

end.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: