Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Trouble when updating a table using model and tableview.

$
0
0
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](3) NULL,       [ACKTTYPE] [char](1) NULL,       [ACKTCODART] [char](18) NULL,       [ACKTCOMART] [char](6) NULL,       [ACKJDATE] [char](8) NULL,       [ACKTHEURE] [char](8) NULL,       [ACCTUTILIS] [char](35) NULL,       [ACCTCOMMEN] [char](200) NULL,       [ACCTETS] [char](2) 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.

Viewing all articles
Browse latest Browse all 13965

Trending Articles