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
Forum Updated to NodeBB v4.3 + New Features

SQL SERVER error syntax

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.0k 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 23 Aug 2017, 03:27 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
    • V Offline
      V Offline
      Vinod Kuntoji
      wrote on 23 Aug 2017, 03:55 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
      • H Offline
        H Offline
        hskoglund
        wrote on 23 Aug 2017, 03:55 last edited by
        #3

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

        1 Reply Last reply
        2

        1/3

        23 Aug 2017, 03:27

        • Login

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