Answer the question
In order to leave comments, you need to log in
Attributes in Russian are to blame?
A record is not added to the database, could it be the fact that the attributes in it are in Russian?
query.prepare("INSERT INTO 'ships' ('Номер_судопотока', 'Наименование_судна', 'Flag','Проект_судна','Состав_судна','Проект_состава','Судовладелец',"
"'Груз_пассажиры','Тоннаж_балласт','Осадка_см','Пункт_отправления','Местоположение_река_км_сх_','Дата_выхода_из_пункты_отправления',"
"'Пункт_назначения','Местоположение_река_км_сх_2','Дата_прибытия_в_пункт_назначения','Дата_отметки_судна_при_пересечении_границы_бассейна',"
"'Наименование_бассейна','Диспетчер') "
"VALUES (:c1, :c2, :c3,:c4,:c5,:c6,:c7,:c8,:c9,:c10,:c11,:c12,:c13,:c14,:c15,:c16,:c17,:c18,:c19)");
query.bindValue(":c1", N_sp);
query.bindValue(":c2", ship_n);
...
query.bindValue(":c19", dispetcher);
query.exec();
if (!query.exec())
{
qDebug() << "Запись не добавлена";
}
model->setTable("ships");
model->select();
ui->tableView->setModel(model);
Answer the question
In order to leave comments, you need to log in
Did you look here? query.lastError().text()
And there should only be one call to query.exec()
In addition to the last mistake, I also found out her number
From there I dug up error 1064, which did not clarify anything, but by typing I realized that the trouble was in the apostrophes that I designated the attributes with. Removed them too.
The next error was the lack of a primary key in the table.
and mismatch of the given types, I designated them as QString, but in the table there were 3 dates and 1 numerical.
Now everything is just fine. Thanks for your help, Igor Dzhulai
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question