我做登录界面,登录时提示为“列名 ‘username’无效”,请问该如何解决
type
Tlogin_form = class(TForm)
Label1: TLabel;
Label2: TLabel;
username_edit: TEdit;
password_edit: TEdit;
CmdOK: TButton;
CmdClose: TButton;
Label3: TLabel;
TADOQuery: TADOQuery;
ADOConnection1: TADOConnection;
procedure CmdOKClick(Sender: TObject);
procedure CmdCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
login_form: Tlogin_form;
name,password,sqlstr:string;
implementationuses main;{$R *.dfm}procedure Tlogin_form.CmdOKClick(Sender: TObject);
begin if (length(trim(username_edit.Text)) > 0) or (length(trim(password_edit.Text)) > 0) then
begin
name:=trim(username_edit.Text);
password:=trim(password_edit.Text);
with TADOQuery.Create(nil) do
try
Connection:=Mainform.ADOConnection1;
Close;
SQL.Clear;
SQL.Add('select * from student where(username like'''+name+''')and(passwor='''+password+''')');
Open;
//如果用户名和密码都正确,则启动相关项目菜单
if RecordCount > 0 then
begin
Mainform.N1.Visible:=true;
Mainform.N2.Visible:=true;
Mainform.N3.Visible:=true;
Mainform.N4.Visible:=true;
Mainform.N11.Enabled:=false;
login_form.free;
end
else
begin
showmessage('请确认登录的用户名和密码是否正确!');
username_edit.SetFocus;
username_edit.SelectAll;
end;
finally
Free;
end;
end
else
begin
showmessage('请输入登录用户名和密码!');
username_edit.SelectAll;
end;
end;
type
Tlogin_form = class(TForm)
Label1: TLabel;
Label2: TLabel;
username_edit: TEdit;
password_edit: TEdit;
CmdOK: TButton;
CmdClose: TButton;
Label3: TLabel;
TADOQuery: TADOQuery;
ADOConnection1: TADOConnection;
procedure CmdOKClick(Sender: TObject);
procedure CmdCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
login_form: Tlogin_form;
name,password,sqlstr:string;
implementationuses main;{$R *.dfm}procedure Tlogin_form.CmdOKClick(Sender: TObject);
begin if (length(trim(username_edit.Text)) > 0) or (length(trim(password_edit.Text)) > 0) then
begin
name:=trim(username_edit.Text);
password:=trim(password_edit.Text);
with TADOQuery.Create(nil) do
try
Connection:=Mainform.ADOConnection1;
Close;
SQL.Clear;
SQL.Add('select * from student where(username like'''+name+''')and(passwor='''+password+''')');
Open;
//如果用户名和密码都正确,则启动相关项目菜单
if RecordCount > 0 then
begin
Mainform.N1.Visible:=true;
Mainform.N2.Visible:=true;
Mainform.N3.Visible:=true;
Mainform.N4.Visible:=true;
Mainform.N11.Enabled:=false;
login_form.free;
end
else
begin
showmessage('请确认登录的用户名和密码是否正确!');
username_edit.SetFocus;
username_edit.SelectAll;
end;
finally
Free;
end;
end
else
begin
showmessage('请输入登录用户名和密码!');
username_edit.SelectAll;
end;
end;
有,我在数据库中定义了 username text
password int
SQL.Add('select * from student where(username like'''+name+''')and(passwor='''+password+''')');
应修改为:
SQL.Add('select * from student where(username like'+''''+name+''''+') and(passwor='+''''+password+''''+')');
试试那个语句是否对》》》》》》》》》》》》》》
而你在数据库中定义了 username text
password int