Problem with data base queries .



  • Hi this piece of code was working fine until I changed the database extension(.db instead of .sqlite) the queries don't want to execute anymore even when the data base is connected.

    Here is the function where I have the problem..

    in this particular function the output result stops in displaying " query is prepared" .

    @void home::on_pushButton_2_clicked()
    {
    QString user_name,password;

    user_name=ui->lineEdit->text();
    password=ui->lineEdit_2->text();
    if(!connOpen()){
        qDebug()<<"failed to open Data Base ";
        return;
    }
    connOpen();
    qDebug()<<("Data base is opened");
    QSqlQuery qry;
    qry.prepare("select * from description_societe where nom='"+user_name+"' and mp='"+password+"' ");
    qDebug()<<("qry is prepared");
    if(qry.exec&#40;&#41;&#41;{
        qDebug()<<("query is executing...");
        int count=0;
        while(qry.next())
        {
            count++;
        }
    
        if(count==1)
        {
           ui->label_16->setText("user_name and password are correct");
           connClose();
           qDebug()<<("connection closed");
           loginEntreprise a;
           this->hide();
           a.setModal(true);
           a.exec&#40;&#41;;
        }
        if(count>1&#41;
        {
            ui->label_16->setText("duplicate user_name or password");
        }
        if(count<1)
        {
            ui->label_16->setText("user_name or password are incorrect");
        }
    
    }
    

    }@

    Thanks in advance.



  • Hi,
    Find here some advices :
    First, connOpen() is called twice,
    The method prepare returns a bool... check it too,
    Use qry.LastError () for more information.
    Bye


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.