Hello,
I am working with the project where I am using 2 QDateEdit and a button.
I need to fetch data between the specified dates, first date is selected from QDateEdit and the second date is from other QdateEdit
One QDateEdit is to select fromdate and the other is to select todate.
I executed the query in Sqlite3 Managment studio,it works but when I send query through Qt problem arrives.
Code:
QString FromcalenderDate,TocalenderDate;
FromcalenderDate=ui->dateEdit->date().toString("yyyy-MM-dd");
qDebug() << FromcalenderDate;
TocalenderDate=ui->dateEdit_2->date().toString("yyyy-MM-dd");
qDebug() << TocalenderDate;
if(!db.isOpen())
{
qDebug()<<"Failed to database open.";return;
}
if(query.exec("SELECT * FROM employees WHERE BirthDate>='"+FromcalenderDate +"' AND BirthDate<='"+TocalenderDate +"' "))
// if(query.exec("SELECT * FROM employees WHERE BirthDate BETWEEN ('"+FromcalenderDate +"' '"+TocalenderDate +"')"))
QString FromcalenderDate,TocalenderDate;
FromcalenderDate=ui->dateEdit->date().toString("yyyy-MM-dd");
qDebug() << FromcalenderDate;
TocalenderDate=ui->dateEdit_2->date().toString("yyyy-MM-dd");
qDebug() << TocalenderDate;
if(!db.isOpen())
{
qDebug()<<"Failed to database open.";return;
}
QSqlQueryModel * modal=new QSqlQueryModel();
QSqlQuery query;
if(query.exec("SELECT * FROM employees WHERE BirthDate>='"+FromcalenderDate +"' AND BirthDate<='"+TocalenderDate +"' "))
// if(query.exec("SELECT * FROM employees WHERE BirthDate BETWEEN ('"+FromcalenderDate +"' '"+TocalenderDate +"')"))
To copy to clipboard, switch view to plain text mode
There is no problem with the database connection as I am getting data for below queries:
if(query.exec("SELECT * FROM employees WHERE BirthDate ='"+FromcalenderDate +"'"))
if(query.exec("SELECT * FROM employees"))
if(query.exec("SELECT * FROM employees WHERE BirthDate ='"+FromcalenderDate +"'"))
if(query.exec("SELECT * FROM employees"))
To copy to clipboard, switch view to plain text mode
I think the problem is I am leaving some some special character or Is there any format to send date to database
Any kind of help is appriciable,
Thanks and Regards,
Lokesh
Bookmarks