unit Unit16;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm16 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Label4: TLabel;
Edit4: TEdit;
ADODataSet1: TADODataSet;
ADOCommand1: TADOCommand;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form16: TForm16;implementation{$R *.dfm}procedure TForm16.Button1Click(Sender: TObject);
var
str:string;
begin
if edit1.Text ='' then
begin
application.MessageBox('用户名不能为空,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit1.SetFocus ;
end;
if edit2.Text ='' then
begin
application.MessageBox('用户密码不能为空,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit2.SetFocus ;
end;
if edit3.Text <> edit4.Text then
begin
application.MessageBox('密码输入错误,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit3.SetFocus ;
end;
if edit1.Text <> vartostr(self.ADODataSet1.Recordset.Fields['user'].Value) then //此句出错程序无法读到数据表,程序无法运行
begin
application.MessageBox('用户名不存在,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit1.SetFocus ;
end;
if edit2.Text <> vartostr(self.ADODataSet1.Recordset.Fields['passwrod'].Value) then///?
begin
application.MessageBox('旧密码输入错误,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit2.SetFocus ;
end;
begin
str:=' update userinfo set user= ' + '''' + self.Edit1.Text + '''' ;
str:=str+' where passwrod= ' + '''' + self.Edit3.Text + '''';
self.ADOCommand1.CommandText:=str;
self.ADOCommand1.Execute;
end;
end;
procedure TForm16.Button2Click(Sender: TObject);
begin
edit1.Text :='';
edit2.Text :='';
edit3.Text :='';
edit4.Text :='';
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm16 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Label4: TLabel;
Edit4: TEdit;
ADODataSet1: TADODataSet;
ADOCommand1: TADOCommand;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form16: TForm16;implementation{$R *.dfm}procedure TForm16.Button1Click(Sender: TObject);
var
str:string;
begin
if edit1.Text ='' then
begin
application.MessageBox('用户名不能为空,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit1.SetFocus ;
end;
if edit2.Text ='' then
begin
application.MessageBox('用户密码不能为空,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit2.SetFocus ;
end;
if edit3.Text <> edit4.Text then
begin
application.MessageBox('密码输入错误,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit3.SetFocus ;
end;
if edit1.Text <> vartostr(self.ADODataSet1.Recordset.Fields['user'].Value) then //此句出错程序无法读到数据表,程序无法运行
begin
application.MessageBox('用户名不存在,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit1.SetFocus ;
end;
if edit2.Text <> vartostr(self.ADODataSet1.Recordset.Fields['passwrod'].Value) then///?
begin
application.MessageBox('旧密码输入错误,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit2.SetFocus ;
end;
begin
str:=' update userinfo set user= ' + '''' + self.Edit1.Text + '''' ;
str:=str+' where passwrod= ' + '''' + self.Edit3.Text + '''';
self.ADOCommand1.CommandText:=str;
self.ADOCommand1.Execute;
end;
end;
procedure TForm16.Button2Click(Sender: TObject);
begin
edit1.Text :='';
edit2.Text :='';
edit3.Text :='';
edit4.Text :='';
end;end.
begin
application.MessageBox('用户名不存在,请重新输入。','错误',mb_ok or mb_iconexclamation);
edit1.SetFocus ;
exit; //加上这句
end;
var
str:String;
begin
ADOQuery1.SQL.Clear;
str:='select user,passwrod from userinfo where user='''+Edit1.Text+'''';
ADOQuery1.SQL.CommaText:=str;
try
ADOQuery1.Open;
if ADOQuery1.IsEmpty then
begin
showmessage('查无此人!');
ADOQuery1.Close;
Exit;
end
else
if Edit2.Text<>ADOQuery1.FieldByName('password').AsString then
begin
showmessage('旧密码错误');
ADOQuery1.Close;
Exit;
end;
except
ADOQuery1.Close;
end; ADOQuery1.Close;
str:='update userinfo set passwrod= ' + '''' + Edit3.Text + '''' ;
str:=str+' where user= ' + '''' + Edit1.Text + '''';
ADOQuery1.SQL.CommaText:=str;
try
ADOQuery1.ExecSQL;
except
end;
ADOQuery1.Close;
end;