Saving Changes back to MS SQL Server
-
Hello All,
My Application does not save changes back to the Database onMannulSubmit and when I change to OnFieldChange, I get the following error:
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated. [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated."
Am using QsqlRelationalTable/QSqlTableModel on the views and additionally QDataWidgetMapper for forms. The connection to MS SQL Server is opened at application startup. Is it a database problem or my coding(below)? Please someone help me!
#include "eclass.h" #include "ui_eclass.h" eClass::eClass(QWidget *parent) : QDialog(parent), ui(new Ui::eClass) { ui->setupUi(this); tableModel(); mapper = new QDataWidgetMapper(this); mapper->setModel(model); mapper->setItemDelegate(new QSqlRelationalDelegate(this)); mapper->addMapping(ui->eID, model->fieldIndex("clNo")); mapper->addMapping(ui->eCode, model->fieldIndex("clCode")); mapper->addMapping(ui->eName, model->fieldIndex("clNam")); mapper->addMapping(ui->eNotes, model->fieldIndex("clDesc")); mapper->addMapping(ui->actv, model->fieldIndex("actv1")); mapper->toLast(); connect(ui->eNew, SIGNAL(clicked()), this, SLOT(addNew())); connect(ui->buttonBox, SIGNAL(accepted()), mapper, SLOT(submit())); } void eClass::tableModel() { model = new QSqlTableModel(this); model->setEditStrategy(QSqlTableModel::OnFieldChange); model->setTable("tblClass"); model->select(); } void eClass::addNew() { int row = mapper->currentIndex(); mapper->submit(); model->insertRow(row); mapper->setCurrentIndex(row); }
-
Hi, it could be that the total size of the 5 fields for your tblClass table is too big, I think the limit is 8192 bytes.
@hskoglund
Thanks for your reply. tblClass is one of the smallest table in the db. There are more than 5field in this table anyway, some fields like ID have not been included in the mapping and the biggest field is clDesc with 100 CHAR.This is my first project with Qt...really how much data could 8192 bytes hold? Am I using the wrong framework for my application? Please advise me...this project has more than 20tables and I have to interact with all of them for data entry, control and reporting....Will I succeed with qt? Thanks in advance.
-
I believe this is a Qt Problem....I have read about the field size scenario with the MS SQL server but I can update well all my tables directly within the server...but when I try inserting new columns or editing with Qt, nothing happens with OnManualSubmit and then the above error is returned OnFieldChange strategy. Please someone with a hint could you hint on this?