delphi做通讯录

delphi做通讯录,第1张

差不多弄出来了

那就是后台数据库已经设计好了嘛

Combobox添加Onchange事件

begin

Edit1.txtL:=combobox1.text

end

修改按钮事件:

with ADOQuery do

begin

close

clear

SQL.Add('Select * from tab where ……'''祥陵棚谨则+Edit1.text+'''')

end

……

就这么简汪则单

给你个例子。

unit Unit1

interface

uses

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

Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls

type

TForm1 = class(TForm)

Edit1: TEdit

Button1: TButton

Button2: TButton

Button3: TButton

DataSource1: TDataSource

ADOQuery1: TADOQuery

DBGrid1: TDBGrid

Button4: TButton

procedure FormCreate(Sender: TObject)

procedure Button1Click(Sender: TObject)

procedure Button2Click(Sender: TObject)

procedure Button3Click(Sender: TObject)

procedure Button4Click(Sender: TObject)

procedure DBGrid1CellClick(Column: TColumn)

private

{ Private declarations }

public

{ Public declarations }

end

var

Form1: TForm1

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject)

var

s:string

begin

s:='select id,sj from fsjl'

form1.ADOQuery1.Close

form1.ADOQuery1.Sql.Clear

form1.ADOQuery1.SQL.Add(s)

form1.ADOQuery1.open

end

procedure TForm1.Button1Click(Sender: TObject) //add

var

s:string

begin

s:='insert into fsjl (sj) values ('''+Edit1.Text+'''行戚)'

ADOQuery1.Close

ADOQuery1.SQL.Clear

ADOQuery1.SQL.Text:=s

ADOQuery1.ExecSQL

Form1.ADOQuery1.Close

Form1.ADOQuery1.SQL.Clear

Form1.ADOQuery1.SQL.Add('select * from fsjl')

Form1.ADOQuery1.Open

end

procedure TForm1.Button2Click(Sender: TObject) //edit

var

s:string

begin

s:='update fsjl set sj ='''+Edit1.Text+''' where id ='''+Form1.ADOQuery1.fieldbyname('id').asstring+''''

ADOQuery1.Close

ADOQuery1.SQL.Clear

ADOQuery1.SQL.Text:=s

ADOQuery1.ExecSQL

Form1.ADOQuery1.Close

Form1.ADOQuery1.SQL.Clear

Form1.ADOQuery1.SQL.Add('select * from fsjl')

Form1.ADOQuery1.Open

end

procedure TForm1.Button3Click(Sender: TObject) //del

var

str:string

id:string

begin

//得到dbgrid某行记录的id

id:=Form1.ADOQuery1.fieldbyname('id').asstring

if id_no=application.MessageBox(pchar('真的要删除ID='+id+'数据吗滑缺?'),'档让陵确认信息',mb_YesNo) then

exit

try

Form1.ADOQuery1.Close

Form1.ADOQuery1.SQL.Clear

str:='delete from fsjl where id='+id

Form1.ADOQuery1.SQL.Add(str)

Form1.ADOQuery1.ExecSQL

showmessage('数据删除成功')

//在dbgrid中显示数据

Form1.ADOQuery1.Close

Form1.ADOQuery1.SQL.Clear

Form1.ADOQuery1.SQL.Add('select * from fsjl')

Form1.ADOQuery1.Open

except

end

end

procedure TForm1.Button4Click(Sender: TObject) //search

var

s:string

begin

s:='select id,sj from fsjl where sj='''+Edit1.Text+''''

form1.ADOQuery1.Close

form1.ADOQuery1.Sql.Clear

form1.ADOQuery1.SQL.Add(s)

form1.ADOQuery1.open

end

procedure TForm1.DBGrid1CellClick(Column: TColumn)//单击事件

begin

Edit1.Text:=Form1.ADOQuery1.fieldbyname('sj').asstring

end

end.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8283792.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存