要求:用delphi7设计了一个登陆界面,数据库是oracle数据库,在oracle的system权限下有一张userinfo的表,表中有两个字段 username 和password ,现在我想通过登陆界面输入用户名和密码,点确定的时候 系统判断是不是userinfo表中的username和password 是得话就跳到下一个窗口,不是的话,就提示错误.求高写个简单点的案例.菜鸟求教.谢谢!

解决方案 »

  1.   

    这个关键是连接oracle数据库,登陆代码网上随便找找就有了
    不想装oracle客户端的话数据库控件用odac
      

  2.   

    oralce边接我自己会.只是不知道代码怎么写.网上也找不到代码,可能我是新手吧.求教了.
      

  3.   

    参考一下
    if Trim(User.Text)<>'' then
    begin
      with adologin do
      begin
        Close;
        SQL.Text:='select * from userinfo where username='''+Trim(user.Text)+''' and password='''+pw.Text+'''';
        Open;
        if not Eof then
        begin
          Form1.show;
          self.Hide;      
        end
        else
        begin
          MessageBox(Handle,'用户名或密码错误!','提示',MB_OK);
          exit;
        end;
    end;
      

  4.   

    procedure TForm1.Button3Click(Sender: TObject);begin
    with adoquery1 do
    begin
      adoquery1.Close;
      ADOQuery1.SQL.clear;
      ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC='''+trim(combobox1.Text)+''' And SPWD='''+Trim(edit1.text)+'''');
      parameters[0].Value:=combobox1.Text;
      parameters[1].Value:=edit1.Text;
      open;
    end;
    if adoquery1.RecordCount<>0 then
       showmessage('登录成功!')
    else showmessage('用户名或密码错误');end;
    end.
    //以上是我自己写的.编译可以过.为什么总是出错呢.请教大人.
      

  5.   

    你用了parameters参数形式,但SQL语句中没有参数
    所以去掉:
    parameters[0].Value:=combobox1.Text;
    parameters[1].Value:=edit1.Text;或者改这句:
    ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC=:A And SPWD=:B');
      

  6.   

    6楼正解   不然谁知道你那个parameters[0],parameters[1]是啥玩意  
      

  7.   

     kaikai_kk老师您好!
     我按你的写法写成如下:
     procedure TForm1.Button3Click(Sender: TObject);begin
    with adoquery1 do
    begin
      adoquery1.Close;
      ADOQuery1.SQL.clear;
      ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC=:A And SPWD=:B');
      open;
    end;
    if adoquery1.RecordCount<>0 then
      showmessage('登录成功!')
    else showmessage('用户名或密码错误');end;
    end.
    还是不对.不过奇怪.怎么总是提示一个错误:
     project project1.exe raised exception class E0leException with message 'ORA-01017'
      

  8.   

    你就按4楼的写就好了啊,干嘛要加个参数呢?
    下面这段代码不是很清晰。
    注:不要加这个:
    parameters[0].Value:=combobox1.Text;
    parameters[1].Value:=edit1.Text;if Trim(User.Text)<>'' then
    begin
      with adologin do
      begin
        Close;
        SQL.Text:='select * from userinfo where username='''+Trim(user.Text)+''' and password='''+pw.Text+'''';
        Open;
        if not Eof then
        begin
          Form1.show;
          self.Hide;      
        end
        else
        begin
          MessageBox(Handle,'用户名或密码错误!','提示',MB_OK);
          exit;
        end;
    end;
      

  9.   

    首先要用一个合法的oracle用户名/密码登录oracle并有权限访问userinfo表,才有楼上几位说的下一步的判断。
    用userinfo中的用户名和密码肯定不能登录Oracle的。
    ORA-01017就是用户/密码错误的提示。