How to deal with foreign key in Qt?



  • @else
    {
    query->prepare ("insert into Courses values (?,?,?)");
    query->bindValue (0,courseIDLine->text ());
    query->bindValue (1,courseNameLine->text ());
    query->bindValue (2,courseTeacherIDLine->text ());

        successful=query->exec ();
    
    }
    
    if(successful)
    {
        closeInsertCourseDlg ();
    }
    else if(!errorMsg->isVisible ())
    {
                //indicate that cannot execute the statement
    }@
    

    but if the SQL statement doesn't satisfy the foreign key, the program will end unexpectedly, saying that the statement have conflicts with foreign key in SQL Server.

    it will not just return a false

    how to change the code??



  • errorMsg is null or otherwise invalid.


Log in to reply
 

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