PDA

View Full Version : QSqlQuery::bndvalue()



akilimob
14th April 2012, 13:29
hello guys can anyone help me out i have a ui dialog that i want users to enter their details and then that data they give is inserted into the database only problem is when i run this code no data is shown in the database although it shows that a new record was inserted.
this is the code:

QSqlQuery qry;
qry.prepare("INSERT INTO [oilsoft].[dbo].[EmployeeStatistics]([EmployeeId],[FirstName],[SirName],[LastName],[Department],[BasicSalary],[Allowances],[NHIF],[NSSF],[Other],[PAYE])VALUES(:EmployeeId,:FirstName,:SirName,:LastName, :Department,:BasicSalary,:Allowances,:NHIF,:NSSF,: Other,:PAYE)");
qry.bindValue(":EmployeeId",ui->employeeIdlineEdit->text());
qry.bindValue(":FirstName",ui->firstnamelineEdit->text());
qry.bindValue(":SirName",ui->sirnamelineEdit->text());
qry.bindValue(":LastName",ui->lastnamelineEdit->text());
qry.bindValue(":Department",ui->departmentlineEdit->text());
qry.bindValue(":BasicSalary",ui->basicsalarylineEdit->text());
qry.bindValue(":Allowances",ui->allowanceslineEdit->text());
qry.bindValue(":NHIF",ui->nhiflineEdit->text());
qry.bindValue(":NSSF",ui->nssflineEdit->text());
qry.bindValue(":Other",ui->otherlineEdit->text());
qry.bindValue(":PAYE",ui->payelineEdit->text());
qry.exec();

wysota
14th April 2012, 20:30
Check if all those line edits contain proper values.

ChrisW67
15th April 2012, 07:40
It seems unlikely that a column named "BasicSalary" or "Allowances" is a VARCHAR (string) column.

You should also get into the habit of checking that your QSqlQuery::exec() calls succeed, i.e. return true, and if not looking at the QSqlQuery::lastError().