Thank you so much for your reply so here is the function add in convention.cpp:
#include "convention.h"
#include "ui_convontion.h"
#include"connexion.h"
#include <QtSql>
#include<QSqlQuery>
#include"QString"
#include<QtSql/QSqlDatabase>
#include<QMessageBox>
convention
::convention(int id_c,
QString nom_entreprise,
int pourcentage_c,
QString date_expiration
)
{
this->id_c=id_c;
this->nom_entreprise=nom_entreprise;
this->pourcentage_c=pourcentage_c;
this->date_expiration=date_expiration;
}
/*convention::~convention()
{
delete ui;
}*/
bool convention::ajouter_convention(convention *c)
{ //bool verif=false;
query.prepare("INSERT INTO CONVENTIONS (id_c,nom_entreprise,pourcentage_c, date_expiration) "
"VALUES (:id_c, :nom_entreprise, :pourcentage_c, :date_expiration");
//verif= query.exec();
query.bindValue(0, c->get_Id_c());
query.bindValue(1,c->get_Nom_entreprise());
query.bindValue(2, c->get_Pourcentage_c());
query.bindValue(3, c->get_date_expiration());
return query.exec();
//verif ;
}
#include "convention.h"
#include "ui_convontion.h"
#include"connexion.h"
#include <QtSql>
#include<QSqlQuery>
#include"QString"
#include<QtSql/QSqlDatabase>
#include<QMessageBox>
convention::convention(int id_c,QString nom_entreprise,int pourcentage_c,QString date_expiration)
{
this->id_c=id_c;
this->nom_entreprise=nom_entreprise;
this->pourcentage_c=pourcentage_c;
this->date_expiration=date_expiration;
}
/*convention::~convention()
{
delete ui;
}*/
bool convention::ajouter_convention(convention *c)
{ //bool verif=false;
QSqlQuery query;
query.prepare("INSERT INTO CONVENTIONS (id_c,nom_entreprise,pourcentage_c, date_expiration) "
"VALUES (:id_c, :nom_entreprise, :pourcentage_c, :date_expiration");
//verif= query.exec();
query.bindValue(0, c->get_Id_c());
query.bindValue(1,c->get_Nom_entreprise());
query.bindValue(2, c->get_Pourcentage_c());
query.bindValue(3, c->get_date_expiration());
return query.exec();
//verif ;
}
To copy to clipboard, switch view to plain text mode
and this is the pushbutton code :
#include "form_ajout_convontion.h"
#include "ui_form_ajout_convontion.h"
#include"convention.h"
#include"QMessageBox"
#include"ui_convontion.h"
#include"connexion.h"
Form_ajout_convontion
::Form_ajout_convontion(QWidget *parent
) : ui(new Ui::Form_ajout_convontion)
{
ui->setupUi(this);
}
Form_ajout_convontion::~Form_ajout_convontion()
{
delete ui;
}
void Form_ajout_convontion::on_pushButton_clicked()
{
int id_c;
int pourcentage_c;
id_c=ui->lineEdit->text().toInt();
nom_entreprise =ui->lineEdit_2->text();
pourcentage_c=ui->lineEdit_3->text().toInt();
date_expiration=ui->lineEdit_4->text();
convention *c =new convention(id_c, nom_entreprise,pourcentage_c, date_expiration) ;
c->ajouter_convention(c);
}
#include "form_ajout_convontion.h"
#include "ui_form_ajout_convontion.h"
#include"convention.h"
#include"QMessageBox"
#include"ui_convontion.h"
#include"connexion.h"
Form_ajout_convontion::Form_ajout_convontion(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form_ajout_convontion)
{
ui->setupUi(this);
}
Form_ajout_convontion::~Form_ajout_convontion()
{
delete ui;
}
void Form_ajout_convontion::on_pushButton_clicked()
{
int id_c;
QString nom_entreprise;
int pourcentage_c;
QString date_expiration ;
id_c=ui->lineEdit->text().toInt();
nom_entreprise =ui->lineEdit_2->text();
pourcentage_c=ui->lineEdit_3->text().toInt();
date_expiration=ui->lineEdit_4->text();
convention *c =new convention(id_c, nom_entreprise,pourcentage_c, date_expiration) ;
c->ajouter_convention(c);
}
To copy to clipboard, switch view to plain text mode
and this is the connexion.cpp code:
#include "mainwindow.h"
#include"connexion.h"
//#include "ui_mainwindow.h"
//#include <QMainWindow>
#include<QDebug>
//#include <QWidget>
#include <QApplication>
#include<QtSql/QSqlDatabase>
#include<QMessageBox>
bool Connexion::create_connection()
{
db.setDatabaseName("mybase");
db.setUserName("hr");
db.setPassword("26113051malek");
//return (db.open());
if (!db.open()) {
qDebug()<<"not connected to database";
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs Oracle support. Please read "
"the Qt OCI driver documentation for information how "
"to build it.\n\n"
return false;
}
else
{
qDebug()<<"connected to database";
return true;
}
}
#include "mainwindow.h"
#include"connexion.h"
//#include "ui_mainwindow.h"
//#include <QMainWindow>
#include<QDebug>
//#include <QWidget>
#include <QApplication>
#include<QtSql/QSqlDatabase>
#include<QMessageBox>
bool Connexion::create_connection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("mybase");
db.setUserName("hr");
db.setPassword("26113051malek");
//return (db.open());
if (!db.open()) {
qDebug()<<"not connected to database";
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs Oracle support. Please read "
"the Qt OCI driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
else
{
qDebug()<<"connected to database";
return true;
}
}
To copy to clipboard, switch view to plain text mode
so , no error is loaded while compiling this code but when i hit the add button this message is written and no adding to the databse happends :
connected to database
QODBCResult::exec: Unable to execute statement: "[Microsoft][Gestionnaire de pilotes ODBC] Erreur de séquence de la fonction"
in the end thank you so much for any help you can give !!!
Bookmarks