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

在开始之前我们先看下功能

运行时:


点击搜索:


点击编辑:


步骤如下:

首先要有安装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.




  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值