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. QODBC with MS SQL

QODBC with MS SQL

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k 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.
  • C Offline
    C Offline
    confused
    wrote on last edited by
    #1

    I am trying to connect to a data base table I already made in Microsoft SQL Server Management Studio Express with Microsoft SQL Server 2005. This is how I am connectiong to it
    @QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("ServerName");
    db.setDatabaseName("DSNname");
    db.setUserName("xxxx");
    db.setPassword("xxxx");
    if (!db.open()) {
    QMessageBox::warning(0, QObject::tr("Database Error"),
    db.lastError().text());
    return false;
    }
    return true;@

    I am not getting a connection error anymore so I think it is connecting to the Data source fine but I can't figure out how to specify the specific database and table to get the information from. I know its there and has some informaiton in it because I ran the sqlbrowser demo and it connected to the correct database without me specifyting it (I assume because it is set as the default database) and then when I opened the table it had the information in it.

    Can anyone tell me how to do this? Also could anyone tell me how to print it out to the screen in a table like form, I am following the guidelines of an example that used SQLITE so maybe its different and thats why?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      Possibly "this":http://doc.qt.nokia.com/4.7-snapshot/sql-tablemodel-tablemodel-cpp.html can help.

      This, Jen, is the internet.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        confused
        wrote on last edited by
        #3

        Thanks! I acctually figured it out by adding the username and password into db.open() so it was db.open("username", "password") I thought that using the 2 statements above that line would have taken care of that but apparently not.

        1 Reply Last reply
        0

        • Login

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