Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Saving Changes back to MS SQL Server
Forum Updated to NodeBB v4.3 + New Features

Saving Changes back to MS SQL Server

Scheduled Pinned Locked Moved General and Desktop
onmannualsubmitsaving to databmssql serversave data to ms
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kyef
    wrote on 22 May 2015, 09:09 last edited by Kyef
    #1

    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);
    }
    

    Kyef Elliot
    If Can Imagine It...I Can Do It!!

    1 Reply Last reply
    0
    • H Online
      H Online
      hskoglund
      wrote on 22 May 2015, 15:29 last edited by
      #2

      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.

      K 1 Reply Last reply 23 May 2015, 07:31
      0
      • H hskoglund
        22 May 2015, 15:29

        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.

        K Offline
        K Offline
        Kyef
        wrote on 23 May 2015, 07:31 last edited by
        #3

        @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.

        Kyef Elliot
        If Can Imagine It...I Can Do It!!

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kyef
          wrote on 23 May 2015, 20:49 last edited by
          #4

          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?

          Kyef Elliot
          If Can Imagine It...I Can Do It!!

          1 Reply Last reply
          0

          1/4

          22 May 2015, 09:09

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved