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. SQL SERVER error syntax
Qt 6.11 is out! See what's new in the release blog

SQL SERVER error syntax

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views
  • 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.
  • H Offline
    H Offline
    hannao
    wrote on last edited by
    #1

    Hello.
    I have problem about sql sever when I run program qt found error.

    [Microsoft][QDBC SQL Server Driver][SQL SERVER] Incorrect syntax near the keyword 'IF'.
    [Microsoft][QDBC SQL Server Driver][SQL SERVER] Incorrect syntax near the keyword 'personal'.
    QODBC3:Unable to execute statement.

    Here my code:
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mDatabase = QSqlDatabase::addDatabase("QODBC");
    mDatabase.setDatabaseName("DRIVER={SQL SERVER};SERVER=IE-ME-0435;DATABASE=employee;"
    "UID=sa;PWD=9094;");
    if(!mDatabase.open())
    {
    QMessageBox::critical(this, "Error", mDatabase.lastError().text());
    return;
    }
    QSqlQuery qry;
    if(!qry.exec("CREATE TABLE IF NOT EXISTS personal"
    "(id INTERGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
    "number TEXT NULL, email TEXT NULL)"))
    {
    QMessageBox::critical(this, "Error", qry.lastError().text());
    return;
    }
    mModel = new QSqlQueryModel(this);
    mModel->setQuery("SELECT * FROM personal");
    ui->tableView->setModel(mModel);
    }
    void MainWindow::on_record_btn_clicked()
    {
    QSqlQuery qry;
    if(!qry.exec(QString("INSERT INTO personal (id, number, email) "
    "VALUES ('%1', %2, %3)")
    .arg(ui->id->text().toInt())
    .arg(ui->number->text())
    .arg(ui->email->text())))
    {
    QMessageBox::critical(this, "Error", qry.lastError().text());
    return;
    }
    mModel->setQuery("SELECT * FROM personal");
    }

    Please help me I do something wrong.

    Thank in Advance!

    1 Reply Last reply
    0
    • Vinod KuntojiV Offline
      Vinod KuntojiV Offline
      Vinod Kuntoji
      wrote on last edited by
      #2

      @hannao said in SQL SERVER error syntax:

      statement

      Which query statement is failing?

      C++, Qt, Qt Quick Developer,
      PthinkS, Bangalore

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #3

        Hi, just guessing but shouldn't it be ".. (id INTEGER.." instead of "... (id INTERGER..."?

        1 Reply Last reply
        2

        • Login

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