Problem in deleting data from the database?
-
Most probably because this is neither valid SQL, nor valid C++.
@
qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
qry.bindValue(":id", id->text().toInt());
qry.bindValue(":cus", cus->toPlainText());
qry.exec();
@
Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.And what has this to do in the Talk > Jobs section?
-
[quote author="Lukas Geyer" date="1326983394"]Most probably because this is neither valid SQL, nor valid C++.
@
qry.prepare("DELETE FROM name WHERE id = ':id' AND cus = ':cus'");
qry.bindValue(":id", id->text().toInt());
qry.bindValue(":cus", cus->toPlainText());
qry.exec();
@
Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.And what has this to do in the Talk > Jobs section?[/quote]
that is i have not noticed mistakenly i have posted in jobs section. Can you move it to desktop section? -
[quote author="Lukas Geyer" date="1326983394"]Most probably because this is neither valid SQL, nor valid C++.
@
qry.prepare("DELETE FROM name WHERE id = ':id' AND cus = ':cus'");
qry.bindValue(":id", id->text().toInt());
qry.bindValue(":cus", cus->toPlainText());
qry.exec();
@
Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.[/quote]
i have tried this but it was not working. -
Try removing the quotes from the query.
@
qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
@Is the database connection opened? See <code>QSqlDatabase::database().isOpen()</code>.
Is there any error issued? See <code>qry.lastError().text()</code>, <code>qry.lastError().driverText()</code>.
What does <code>qry.prepare(...)</code> return?
Are the values bound correctly? See <code>qry.boundsValues()</code>.
Is there even a dataset with the given <code>id</code> and <code>cus</code> that can be deleted?
Do both, <code>id->text().toInt()</code> and <code>cus->toPlainText()</code>, contain reasonable values? -
[quote author="Lukas Geyer" date="1327040840"]Try removing the quotes from the query.
@
qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
@Is the database connection opened? See <code>QSqlDatabase::database().isOpen()</code>.
Is there any error issued? See <code>qry.lastError().text()</code>, <code>qry.lastError().driverText()</code>.
What does <code>qry.prepare(...)</code> return?
Are the values bound correctly? See <code>qry.boundsValues()</code>.
Is there even a dataset with the given <code>id</code> and <code>cus</code> that can be deleted?
Do both, <code>id->text().toInt()</code> and <code>cus->toPlainText()</code>, contain reasonable values?[/quote]i have checked the code actually the deleting problem was coming only when i was using the function of QTableView
@ QTableView::resizeRowtoContents()@
I didn't understand why this was creating problem in deleting. Do you have any idea on that? -
[quote author="pratik041" date="1327142033"]I didn't understand why this was creating problem in deleting.[/quote]
Me neither.
Please add the things I've mentioned in my previous post to your code and try to find out what's actually the difference between those queries working and those queries not working.
And what does "not working" mean for you at all? Is there an error when the query is executed or is the query executed correctly and the record is just not removed?