我是新手不熟悉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.

解决方案 »

  1.   

    Query1.Close;//首先关闭数据集
        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;
      

  2.   

    这些使判断你的两个输入框的信息,你应该看的懂!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('请输入用户名')
      

  3.   

    我的数据库中的表是 “用户信息表” 
       
      字段是  用户名、密码
    现有数据是  admin  123456上面程序是我写的,调试的时候说
    SQL admin 列名 无效。 我不明白的是Query1  select出来的信息 怎么和我的IWEdit1.Text 输入的信息去比较,是这句吗?
    Query1.FieldByName('密码').AsString=p
      

  4.   

    SQL admin 列名 无效  晕~! 这个错误不知道怎么解决以上的程序还是无法验证我的用户和密码另外Query1 的属性里SQL要不要 写语句啊?
      

  5.   

    把 
    Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');
    改为
    Query1.SQL.Add('select * from 用户信息表 where 用户名='+#39+u+#39);
    再试
      

  6.   

    那你可以这样写呀!
    if Query1.Locate('用户名',IWEdit1.Text,[]) then
      

  7.   

    IWEdit1.Text:='';
    IWEdit2.Text:='';
    Query1.Active:=true;放再窗体初始化里
      

  8.   

    Query1.SQL.Add('select * from 用户信息表 ’);
    Query1.SQL.Add('where 用户名='''+u+'''');
      

  9.   

    因为你要连接字符串呀!
    delphi中一个单引号要用两个双引号表示!
      

  10.   

    Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');
    //这句话没什么作用,用户这个字段应该是唯一的,根据他定位到相应的行以后,在校验密码字段。
      

  11.   

    #39 表示单引号的ANSII码
    + 是连接的意思!
      

  12.   

    问题出在 Query1.SQL.Add('select * from 用户信息表 where 用户名='+u+'');Query1.SQL.Add('select * from 用户信息表 where 用户名=“'+u+'”');
      

  13.   

    你的代码很乱, 很容易出错!!建议用如下结构if XXX then
    begin
      showmessage('yyy');
      exit;
    end;
    ...修改
    Query1.SQL.Add('select * from 用户信息表 where 用户名=''+u+'''');