The following code creates a table and stuffs the database with data. When running the below code, I receive an error 'Parameter count mismatch' on query.exec(). However, if I use the commented line instead, everything works fine. How am I misusing the prepare feature?
QSqlQuery query;
if (query.exec("CREATE TABLE Users ( u_ID INT IDENTITY(1,1) PRIMARY KEY, cName varchar(25) UNIQUE )"))
{
for (int i=1;i<=100;++i)
{
QString uName;
uName = "user" + QString::number(i);
query.prepare("INSERT INTO Users (cName) VALUES(':UNAME')");
query.bindValue(":UNAME",uName);
query.exec();
//query.exec("INSERT INTO Users (cName) VALUES('" + uName + "')");
if (query.lastError().isValid()){
QMessageBox::information(0,"ERR!",query.lastError().text());
}
}
}