尘中客的博客

无所从来 亦无所去 相遇随缘 聚散随意

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.




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/s371795639/article/details/53991759
个人分类: Delphi
想对作者说点什么? 我来说一句

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

不良信息举报

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

最多只允许输入30个字

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