windsword
20th August 2009, 14:19
Hello!
If i use the following code in a Slot callback I am able to read from mysql database:
QSqlQuery query;
query.exec("SELECT LastName FROM Experimenters WHERE ExpUserName='sag686'");
while (query.next()) {
QString exper = query.value(0).toString();
qDebug() << exper;
}
But if I use the following to Write to the database, I get error, any hints into what I might be doing wrong? The strings come from a Form's LineEdit fields.
QSqlQuery query;
query.prepare( "INSERT INTO Clients (ExpUserName, Password, FirstName, LastName,Email, Phone, CreateDate, LastModified, HarpGroup, isActive) VALUES (:ExpUserName,:Password, :FirstName, :LastName, :Email, :Phone, :CreateDate, :LastModified, :HarpGroup, :isActive)");
query.bindValue( ":ExpUserName", expUserIDEdit->displayText() );
query.bindValue( ":Password", passwordEdit->displayText() );
query.bindValue( ":FirstName", firstnameEdit->displayText() );
query.bindValue( ":LastName", lastnameEdit->displayText() );
query.bindValue( ":Email", emailEdit->displayText() );
query.bindValue( ":Phone", phoneEdit->displayText() );
query.bindValue( ":CreateDate", QDate::currentDate().toString("dd,mm,yyyy") );
query.bindValue( ":LastModified", QDate::currentDate().toString("dd,mm,yyyy") ) ;
query.bindValue( ":HarpGroup", harpGroupCB->currentText() );
query.bindValue( ":isActive", 1);
if(!query.exec())
qDebug() << "> Query exec() error." << query.lastError();
else
qDebug() << ">Query exec() success.";
If i use the following code in a Slot callback I am able to read from mysql database:
QSqlQuery query;
query.exec("SELECT LastName FROM Experimenters WHERE ExpUserName='sag686'");
while (query.next()) {
QString exper = query.value(0).toString();
qDebug() << exper;
}
But if I use the following to Write to the database, I get error, any hints into what I might be doing wrong? The strings come from a Form's LineEdit fields.
QSqlQuery query;
query.prepare( "INSERT INTO Clients (ExpUserName, Password, FirstName, LastName,Email, Phone, CreateDate, LastModified, HarpGroup, isActive) VALUES (:ExpUserName,:Password, :FirstName, :LastName, :Email, :Phone, :CreateDate, :LastModified, :HarpGroup, :isActive)");
query.bindValue( ":ExpUserName", expUserIDEdit->displayText() );
query.bindValue( ":Password", passwordEdit->displayText() );
query.bindValue( ":FirstName", firstnameEdit->displayText() );
query.bindValue( ":LastName", lastnameEdit->displayText() );
query.bindValue( ":Email", emailEdit->displayText() );
query.bindValue( ":Phone", phoneEdit->displayText() );
query.bindValue( ":CreateDate", QDate::currentDate().toString("dd,mm,yyyy") );
query.bindValue( ":LastModified", QDate::currentDate().toString("dd,mm,yyyy") ) ;
query.bindValue( ":HarpGroup", harpGroupCB->currentText() );
query.bindValue( ":isActive", 1);
if(!query.exec())
qDebug() << "> Query exec() error." << query.lastError();
else
qDebug() << ">Query exec() success.";