我插入数据怎么没有反映?但是Showmessage('该用户名已存在,请重新输入!');可以实现。谢谢!!!!procedure TFormyhzc.Button1Click(Sender: TObject);
begin
    with  DataModulenjsh do
    begin
        ADOQueryyhzc.Close;
        ADOQueryyhzc.SQL.Clear;
        ADOQueryyhzc.SQL.Text := 'select username from tableyhmm where username = '''+ Edit1.Text +  '''';
        ADOQueryyhzc.open;
    
     if ADOQueryyhzc.RecordCount <> 0 then
              begin
                  Showmessage('该用户名已存在,请重新输入!');
                  Edit1.Clear;
                  Edit2.Clear;
                  Edit1.SetFocus;
              end     else  if ADOQueryyhzc.RecordCount = 0  then
             begin
                  if not ADOQueryyhzc.Eof then
                       begin
                            try
                              ADOQueryyhzc.Close;
                              ADOQueryyhzc.SQL.Clear;
                              ADOQueryyhzc.SQL.Add('INSERT INTO TABLEyhmm(username,userpassword)');
                              ADOQueryyhzc.SQL.Add(' VALUES(:username,:userpassword)');
                              ADOQueryyhzc.Parameters.ParamByName('username').Value:= Edit1.Text;
                              ADOQueryyhzc.Parameters.ParamByName('userpassword').Value:= Edit2.Text;
                              ADOQueryyhzc.Open;                              Showmessage('注册成功!');
                              Formyhdl.Show;
                            except
                              showmessage('注册失败!');
                            end;
                            Formyhzc.Close;
                      end 
                else
                      ADOQueryyhzc.Next;
end;
end;
end;

解决方案 »

  1.   

    ...
                               try
                                  ADOQueryyhzc.Close;
                                  ADOQueryyhzc.SQL.Clear;
                                  ADOQueryyhzc.SQL.Add('INSERT INTO TABLEyhmm(username,userpassword)');
                                  ADOQueryyhzc.SQL.Add(' VALUES(:username,:userpassword)');
                                  ADOQueryyhzc.Parameters.ParamByName('username').Value:= Edit1.Text;
                                  ADOQueryyhzc.Parameters.ParamByName('userpassword').Value:= Edit2.Text;
                                  ADOQueryyhzc.Open;------------>ADOQueryyhzc.ExecSql........
      

  2.   

    ADOQueryyhzc.Open;------------>ADOQueryyhzc.ExecSql插入数据不能用open
      

  3.   

    我早换成ADOQueryyhzc.ExecSql了
    但是不管输入什么,显示的都是:‘该用户名已存在,请重新输入!’
      

  4.   

    这个程序不应该使用if not ADOQueryyhzc.Eof 和ADOQueryyhzc.Next;这个循环语句,因为1。当执行ADOQueryyhzc.RecordCount = 0这一句时,数据集焦点显然已在末尾,所以加上这句话后,if中的程序是不会执行的!2。程序运行recordcount时,自然对数据进行了全部的搜索啊!