delphi 登陆 代码

来源:百度知道 编辑:UC知道 时间:2024/05/14 04:06:57
新手真不容易啊,我用了一天的时间做个登陆界面的代码,一直到现在晚上2点40了,还没做好,我也没办法,只好到这问了,完了就去睡觉了,累死我啦。
我的代码是这样的,运行后,出现提示:
"不正常的定义参数对象。提供了不一致或不完整的信息"

(access)数据库的设计是一个user表,里面有username,password字段,有一个admin,admin数据
在form1上就一个用户名输入,一个密码输入,还有个登陆按钮,用了个adoquery,连接都设置好了

代码开始:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
u,p:string;

implementation

procedure TForm1.Button1Click(Sender: TObject);
begin
{
if(trim(Edit1.Text)='')and(trim(Edit2.Text)='') then
Application.Messagebox('必须输入用户名和密码','提示',64)
else if(trim(Edit1.Text)<>'')and(trim(Edit2.Text)='') then
Application.Messagebox('请输入密码','提示',64)
else if(trim(Edit1.Text)='')and(trim(Edit2.Text)<>'') then
Application.Messagebox('请输入用户名','提示',64)
else
} //这些代码不要了,太繁琐!改成下面的。
if(trim(Edit1.Text)='') or (trim(Edit2.Text)='') then
begin
Application.Messagebox('必须输入用户名和密码','提示',64);
Exit;
end
else
//你的代码太啰唆了,改成这样好些。
begin
u:=Edit1.Text;
p:=Edit2.Text;
adoquery1.Close;
{adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from user where username=:u');}
adoquery1.SQL.Text := 'select * from user where username=''&#