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.
  • KyefK Offline
    KyefK Offline
    Kyef
    wrote on 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
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on 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.

      KyefK 1 Reply Last reply
      0
      • hskoglundH hskoglund

        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.

        KyefK Offline
        KyefK Offline
        Kyef
        wrote on 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
        • KyefK Offline
          KyefK Offline
          Kyef
          wrote on 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

          • Login

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