delphi 数据库 连接 查询 修改 的实现

delphi 数据库 连接 查询 修改 的实现,第1张

unit Unit1

interface

uses

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

Dialogs, DB, StdCtrls, Grids, DBGrids, DBTables

type

TForm1 = class(TForm)

Query1: TQuery

DBGrid1: TDBGrid

Edit1: TEdit

Label1: TLabel

Button1: TButton

DataSource1: TDataSource

GroupBox1: TGroupBox

RadioButton1: TRadioButton

RadioButton2: TRadioButton

GroupBox2: TGroupBox

Edit2: TEdit

Edit4: TEdit

Button2: TButton

Button3: TButton

Button4: TButton

Button5: TButton

Button6: TButton

Label2: TLabel

Label3: TLabel

Label4: TLabel

Edit3: TEdit

RadioButton3: TRadioButton

Button7: TButton

procedure FormCreate(Sender: TObject)

procedure Button1Click(Sender: TObject)

procedure Button6Click(Sender: TObject)

procedure Button2Click(Sender: TObject)

procedure Button3Click(Sender: TObject)

procedure Button5Click(Sender: TObject)

procedure Button4Click(Sender: TObject)

procedure Button7Click(Sender: TObject)

private

{ Private declarations }

public

{ Public declarations }

end

var

Form1: TForm1

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject)

begin

radiobutton3.checked:=true

end

procedure TForm1.Button1Click(Sender: TObject)

begin

query1.close

query1.sql.clear

if radiobutton1.checked then

query1.sql.add('select * from stu where sname='''+edit1.text+'''')

if radiobutton2.checked then

query1.sql.add('select * from stu where grade='''+edit1.text+'''')

if radiobutton3.checked then

query1.sql.add('select * from stu where sno='''+edit1.text+'''')

query1.open

end

procedure TForm1.Button6Click(Sender: TObject)

begin

application.Terminate

end

procedure TForm1.Button2Click(Sender: TObject)

begin

edit2.Enabled:=true

edit3.Enabled:=true

edit4.Enabled:=true

edit2.SetFocus

button7.Enabled:=true

button4.Enabled:=true

button5.Enabled:=true

button4.Visible:=true

button7.Visible:=false

end

procedure TForm1.Button3Click(Sender: TObject)

begin

edit2.Enabled:=true

edit3.Enabled:=true

edit4.Enabled:=true

button7.Enabled:=true

button4.Enabled:=true

button5.Enabled:=true

button4.Visible:=false

button7.Visible:=true

edit2.Text:=query1.fieldbyname('sno').AsString

edit3.Text:=query1.fieldbyname('sname').AsString

edit4.Text:=query1.fieldbyname('grade').AsString

edit2.SetFocus

end

procedure TForm1.Button5Click(Sender: TObject)

begin

edit2.Text:=''

edit3.Text:=''

edit4.Text:=''

edit2.Enabled:=false

edit3.Enabled:=false

edit4.Enabled:=false

button4.Enabled:=false

button5.Enabled:=false

end

procedure TForm1.Button4Click(Sender: TObject)

begin

if edit2.Text='' then

begin

showmessage('请输入学号!')

exit

end

if edit3.Text='' then

begin

showmessage('请输入姓名!')

exit

end

if edit4.Text='' then

begin

showmessage('请输入成绩!')

exit

end

query1.close

query1.sql.clear

query1.sql.add('insert into stu(sno,sname,grade)')

query1.SQL.Add('values(:xh,:name,:cj)')

query1.ParamByName('xh').Value:=edit2.text

query1.ParamByName('name').Value:=edit3.text

query1.ParamByName('cj').Value:=edit4.text

query1.ExecSQL

query1.Close

query1.SQL.Clear

query1.SQL.Add('select * from stu')

query1.Open

button4.Enabled:=false

button7.Enabled:=false

button5.Enabled:=false

end

procedure TForm1.Button7Click(Sender: TObject)

var

str:string

begin

if edit2.Text='' then

begin

showmessage('请输入学号!')

exit

end

if edit3.Text='' then

begin

showmessage('请输入姓名!')

exit

end

if edit4.Text='' then

begin

showmessage('请输入成绩!')

exit

end

str:=query1.fieldbyname('sno').AsString

query1.close

query1.sql.clear

query1.sql.add('delete from stu')

query1.SQL.Add('where sno='''+str+'''')

query1.ExecSQL

query1.close

query1.sql.clear

query1.sql.add('insert into stu(sno,sname,grade)')

query1.SQL.Add('values(:xh,:name,:cj)')

query1.ParamByName('xh').Value:=edit2.text

query1.ParamByName('name').Value:=edit3.text

query1.ParamByName('cj').Value:=edit4.text

query1.ExecSQL

query1.Close

query1.SQL.Clear

query1.SQL.Add('select * from stu')

query1.Open

button4.Enabled:=false

button7.Enabled:=false

button5.Enabled:=false

end

end.

ADOQuery1.Close

ADOQuery1.SQL.Clear

ADOQuery1.SQL.Text:='select * from 用户权限 where 用户名='''+user+'''and 密码='''+pass+''''

//'select * from 用户权限 where 用户名='''+user.Trim()+'''and 密码='''+pass.Trim()++'''' Adoquery1.Open

//if not adoquery1.Eof

begin

temp:=adoquery1.FieldByName('权限序号').AsString

end

这样试试

SQLConnection1.Params.clear

然后再添上你自己修改的值

SQLConnection1.Params.Values['ServerName'] := '192.168.0.112'

SQLConnection1.Params.Values['Database'] := 'trackData'

SQLConnection1.Params.Values['User_Name'] := 'sa'

SQLConnection1.Params.Values['Password'] := '123456'

SQLConnection1.Open


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

原文地址: http://outofmemory.cn/sjk/10773596.html

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

发表评论

登录后才能评论

评论列表(0条)

保存