How to use ADODB.Connection in Qt and query database?

As shown in my previous post, QODBC / QODBC3 does not work very well with databases. I found a suggestion of the year here for using ADODB for SQL Server. Can someone show an example or offer a link explaining How to connect, request and get the result using ADODB.Connection in Qt?

+5
source share
1 answer

You need to use QAxObject .

First you should take a look at:

Here is a sample code to get you started:

 // Create connection QAxObject *connection = new QAxObject("ADODB.Connection"); connection->dynamicCall("Open(\"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Inaz;Data Source=SERVER02\")"); // Execute query and get recordset QAxObject *recordSet = connection->querySubObject("Execute(\"select column01 from table01\")"); // Get fields // or check https://msdn.microsoft.com/en-us/library/ms681510(v=vs.85).aspx to see what you can do with and how to use a recordset QAxObject *fields = recordSet->querySubObject("Fields"); 

Note. To use ADODB, you need to call CoInitialize . However, QGuiApplication and QApplication call it internally, so you may not always need to call yourself.

+1
source

Source: https://habr.com/ru/post/1261429/


All Articles