首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

登陆代码有关问题啊找到的进,给点意见和建议

2012-02-29 
登陆代码问题啊?????找到的进,给点意见和建议问个问题啊我用dblookupcombobox做的数据库用户名显示,在里面

登陆代码问题啊?????找到的进,给点意见和建议
问个问题啊
我用dblookupcombobox做的数据库用户名显示,在里面选择一个用户名,在edit中输入密码,如果验证正确的话,上面有个lable3的caption显示当前的用户名,否则不显示,会出现一个message
当我第一次选择完用户名,输入密码完成以后显示为正确的用户名,我再输入一个错误的密码以后,就没有反映了,怎么回事  
unit   Unit1;

interface

uses
    Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
    Dialogs,   DB,   ADODB,   StdCtrls,   DBCtrls;

type
    TForm1   =   class(TForm)
        ADOConnection1:   TADOConnection;
        DataSource1:   TDataSource;
        ADOTable1:   TADOTable;
        Label1:   TLabel;
        Label2:   TLabel;
        DBLookupComboBox1:   TDBLookupComboBox;
        Edit1:   TEdit;
        Button1:   TButton;
        Button2:   TButton;
        Label3:   TLabel;
        procedure   FormCreate(Sender:   TObject);
        procedure   Button1Click(Sender:   TObject);
    private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;

var
    Form1:   TForm1;
    eduser:string;
    edpsd:string;
    flage:boolean;


implementation

{$R   *.dfm}

procedure   TForm1.FormCreate(Sender:   TObject);
begin
adotable1.Active:=true;
label3.caption:= ' ';
flage:=false;
end;

procedure   TForm1.Button1Click(Sender:   TObject);
  var
  username:string;
begin
label3.caption:= ' ';

repeat
username:=dblookupcombobox1.text;
eduser:=adotable1.FieldByName( 'name ').AsString;
edpsd:=   adotable1.FieldByName( 'psw ').asstring;
if   (eduser=username)then
    if   (edpsd=edit1.text)then
    flage:=true;
adotable1.Next;
until   adotable1.Eof;
if   flage=true   then
  label3.caption:=dblookupcombobox1.text
  else
    showmessage( '密码错误 ');
    edit1.Text:= ' '   ;
end;

end.

[解决办法]
你看看你的数据集的指针到那里去了呢?
//A点
repeat
username:=dblookupcombobox1.text;
eduser:=adotable1.FieldByName( 'name ').AsString;
edpsd:= adotable1.FieldByName( 'psw ').asstring;
if (eduser=username)then
if (edpsd=edit1.text)then
flage:=true;
adotable1.Next;
until adotable1.Eof;
第一次运行,系统到达A点的时候,记录的指针在第一个,然后你可以遍历这个数据集得到正确的判断,那么第二次运行的时候,记录的指针已经不在第一个了,所以也许你根本就遍历不到你所需要的那条记录!
在A点加上一个adotable1.first试试呢?

热点排行