Trouble when updating a table using model and tableview.



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



  • No one has any idea?


  • Lifetime Qt Champion

    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)



  • I tried in 4.8.4
    I tried in 5.0.2

    I've got the same error.


  • Lifetime Qt Champion

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.