我是新手不熟悉Query的用法~!请高手帮忙改改~!
unit UnitLogin;
{PUBDIST}interfaceuses
IWAppForm, IWApplication, IWTypes, IWCompEdit, IWDBStdCtrls, IWCompLabel,
Classes, Controls, IWControl, IWExtCtrls, IWCompRectangle, DB, SysUtils,
DBTables;type
TformLogin = class(TIWAppForm)
IWImageFile1: TIWImageFile;
IWLabel1: TIWLabel;
IWLabel2: TIWLabel;
IWLabel3: TIWLabel;
IWImageFile2: TIWImageFile;
IWImageFile3: TIWImageFile;
Query1: TQuery;
IWEdit1: TIWEdit;
IWEdit2: TIWEdit;
procedure IWImageFile3Click(Sender: TObject);
procedure IWImageFile2Click(Sender: TObject);
public
end;implementation
{$R *.dfm}uses
ServerController, UnitFunction, UnitHelp;procedure TformLogin.IWImageFile3Click(Sender: TObject);
begin
IWEdit1.Text:='';
IWEdit2.Text:='';
end;procedure TformLogin.IWImageFile2Click(Sender: TObject);
var
u,p:string;
begin if(trim(IWEdit1.Text)='')and(trim(IWEdit2.Text)='') then
WebApplication.ShowMessage('必须输入用户名和密码')
else if(trim(IWEdit1.Text)<>'')and(trim(IWEdit2.Text)='') then
WebApplication.ShowMessage('请输入密码')
else if(trim(IWEdit1.Text)='')and(trim(IWEdit2.Text)<>'') then
WebApplication.ShowMessage('请输入用户名')
else
begin
u:=IWEdit1.Text;
p:=IWEdit2.Text;
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');
Query1.Open;
Query1.Active:=true;
if Query1.FieldByName('密码').AsString=p then
begin
//登陆成功
Query1.Close;
Move(TformHelp); //调用自定义函数进入新界面
end
else
begin
//登陆失败
Query1.Close;
WebApplication.ShowMessage('请输入正确的用户名和密码');
end;
end; //
end;end.
unit UnitLogin;
{PUBDIST}interfaceuses
IWAppForm, IWApplication, IWTypes, IWCompEdit, IWDBStdCtrls, IWCompLabel,
Classes, Controls, IWControl, IWExtCtrls, IWCompRectangle, DB, SysUtils,
DBTables;type
TformLogin = class(TIWAppForm)
IWImageFile1: TIWImageFile;
IWLabel1: TIWLabel;
IWLabel2: TIWLabel;
IWLabel3: TIWLabel;
IWImageFile2: TIWImageFile;
IWImageFile3: TIWImageFile;
Query1: TQuery;
IWEdit1: TIWEdit;
IWEdit2: TIWEdit;
procedure IWImageFile3Click(Sender: TObject);
procedure IWImageFile2Click(Sender: TObject);
public
end;implementation
{$R *.dfm}uses
ServerController, UnitFunction, UnitHelp;procedure TformLogin.IWImageFile3Click(Sender: TObject);
begin
IWEdit1.Text:='';
IWEdit2.Text:='';
end;procedure TformLogin.IWImageFile2Click(Sender: TObject);
var
u,p:string;
begin if(trim(IWEdit1.Text)='')and(trim(IWEdit2.Text)='') then
WebApplication.ShowMessage('必须输入用户名和密码')
else if(trim(IWEdit1.Text)<>'')and(trim(IWEdit2.Text)='') then
WebApplication.ShowMessage('请输入密码')
else if(trim(IWEdit1.Text)='')and(trim(IWEdit2.Text)<>'') then
WebApplication.ShowMessage('请输入用户名')
else
begin
u:=IWEdit1.Text;
p:=IWEdit2.Text;
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');
Query1.Open;
Query1.Active:=true;
if Query1.FieldByName('密码').AsString=p then
begin
//登陆成功
Query1.Close;
Move(TformHelp); //调用自定义函数进入新界面
end
else
begin
//登陆失败
Query1.Close;
WebApplication.ShowMessage('请输入正确的用户名和密码');
end;
end; //
end;end.
Query1.SQL.Clear;//然后将它的SQL属性中的 SQL语句清空
Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');//接着加入你要执行的语句(这句意思是说你要查询的用户名是u)
Query1.Open;//然后打开数据集
Query1.Active:=true;//给Query初始化为真使它能够和数据表连接
if Query1.FieldByName('密码').AsString=p then//判断你所查询的密码是否为p
begin
//登陆成功
Query1.Close;//登陆成功关闭数据集,以免数据被修改
Move(TformHelp); //调用自定义函数进入新界面
end
else
begin
//登陆失败
Query1.Close;
WebApplication.ShowMessage('请输入正确的用户名和密码');
end;
WebApplication.ShowMessage('必须输入用户名和密码')
else if(trim(IWEdit1.Text)<>'')and(trim(IWEdit2.Text)='') then//密码不能为空
WebApplication.ShowMessage('请输入密码')
else if(trim(IWEdit1.Text)='')and(trim(IWEdit2.Text)<>'') then//用户名不能为空
WebApplication.ShowMessage('请输入用户名')
字段是 用户名、密码
现有数据是 admin 123456上面程序是我写的,调试的时候说
SQL admin 列名 无效。 我不明白的是Query1 select出来的信息 怎么和我的IWEdit1.Text 输入的信息去比较,是这句吗?
Query1.FieldByName('密码').AsString=p
Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');
改为
Query1.SQL.Add('select * from 用户信息表 where 用户名='+#39+u+#39);
再试
if Query1.Locate('用户名',IWEdit1.Text,[]) then
IWEdit2.Text:='';
Query1.Active:=true;放再窗体初始化里
Query1.SQL.Add('where 用户名='''+u+'''');
delphi中一个单引号要用两个双引号表示!
//这句话没什么作用,用户这个字段应该是唯一的,根据他定位到相应的行以后,在校验密码字段。
+ 是连接的意思!
begin
showmessage('yyy');
exit;
end;
...修改
Query1.SQL.Add('select * from 用户信息表 where 用户名=''+u+'''');