看了那篇关于Qt数据库(六)QSqlTableModel的文章http://apps.hi.baidu.com/share/detail/21601879关于删除记录的语句,点击删除按钮后,被选中的记录项没有被删除。可以帮我分析一下...
看了那篇关于Qt数据库(六)QSqlTableModel的文章
http://apps.hi.baidu.com/share/detail/21601879
关于删除记录的语句,点击删除按钮后,被选中的记录项没有被删除。可以帮我分析一下吗?代码如下:
void MainWindow::on_deleteBn_clicked()
{
int curRow=ui->tableView->currentIndex().row();
model->removeRow(curRow);
model->submitAll();
}
错误提示:QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver][SQL Server]将 nvarchar 值 '由东向西 ' 转换为数据类型为 int 的列时发生语法错误。"
建立表的语句如下:
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
//db.setDatabaseName(dsn);
QString dsn= QString::fromLocal8Bit("fSQLServer");
db.setDatabaseName(dsn);
if(!db.open()){
QMessageBox::about(0,QObject::tr("Database Error"),db.lastError().text());
return false;
}
else{
QMessageBox::information(0,"Connect Database","connect success!",QMessageBox::Ok);
QSqlQuery query(db);
query.exec("if exists table student drop table student");
query.exec("create table student('Date' datetime ,'Address' char(20),'Direction' char(20),'Speed' int,'LimitedSpeed' int) value(?,?,?,?,?)");
return true;
}
把model->submitAll()这句注销后,没有出现上述错误,可是也是一样删除不了。
展开