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. Trouble when updating a table using model and tableview.

Trouble when updating a table using model and tableview.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.6k 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.
  • G Offline
    G Offline
    GuiTwo
    wrote on last edited by
    #1

    Hi,

    I'm new at qt-project... so I will start by presenting myself.
    My name is Guillaume
    I'm French (Sorry for the spelling)
    I'm coding for the fun.

    I'm having issue when I try to update a a table using model and tableview.
    I'm using Qt 4.8.3.
    and SQL Server 2008 R2

    Here is my table

    @CREATE TABLE [dbo].[ACTITRAC](
    [ACKTSOC] char NULL,
    [ACKTTYPE] char NULL,
    [ACKTCODART] char NULL,
    [ACKTCOMART] char NULL,
    [ACKJDATE] char NULL,
    [ACKTHEURE] char NULL,
    [ACCTUTILIS] char NULL,
    [ACCTCOMMEN] char NULL,
    [ACCTETS] char NULL
    )
    @

    Here is my Qt code:

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("Driver={SQL Server};Server=XSOFTWAR-0B291A;Database=200JUR;Port=1433;WSID=.");
    
    QMessageBox msg;
    if (db.open())
    {
        msg.setText("Connection successfull");
    
    }
    else
    {
        msg.setText(db.lastError().text());
    }
    
    QSqlTableModel *model = new QSqlTableModel(this);
    model->setTable("ACTITRAC");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    
    QTableView *view = new QTableView();
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(view);
    centralWidget()->setLayout(layout);
    
    view->setModel(model);
    view->show();
    

    }@

    Here the error:
    @QODBCResult::exec: Unable to execute statement: "[Microsoft][SQL Server Native Client 10.0][SQL Server]The data types char and ntext are incompatible in the equal to operator. [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared."@

    I can understand the error with the SQL request from the SQL profiler:
    @exec sp_executesql N'UPDATE ACTITRAC SET "ACCTCOMMEN"=@P1 WHERE "ACKTSOC" = @P2 AND "ACKTTYPE" = @P3 AND "ACKTCODART" = @P4 AND "ACKTCOMART" = @P5 AND "ACKJDATE" = @P6 AND "ACKTHEURE" = @P7 AND "ACCTUTILIS" = @P8 AND "ACCTCOMMEN" = @P9 AND "ACCTETS" = @P10',N'@P1 ntext,@P2 nvarchar(6),@P3 nvarchar(2),@P4 nvarchar(36),@P5 nvarchar(12),@P6 nvarchar(16),@P7 nvarchar(16),@P8 nvarchar(70),@P9 ntext,@P10 nvarchar(4)',N'Régénération de facture client ',N'100',N'2',N'010775 ',N' ',N'20120724',N'14314130',N'Frédérique BONNIN FRE ',N'Régénération de facture client ',N' '@

    What I can't understand is why the 9th parameter is a ntext.
    If someone as any idea.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GuiTwo
      wrote on last edited by
      #2

      No one has any idea?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Unless you are locked to this Qt version you should try again with the latest version.

        If it still doesn't help, you can try to ask on the interest mailing list you'll find Qt's developers/maintainers there (this forum is more user oriented)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GuiTwo
          wrote on last edited by
          #4

          I tried in 4.8.4
          I tried in 5.0.2

          I've got the same error.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Not to be picky but both these versions are not the latest 4.8.5 and 5.2.0 are

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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