<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MS Access and QSqlQuery]]></title><description><![CDATA[<p dir="auto">Hi everyone! My english is not very good but i'll try to describe my problem.<br />
So, i have primitive code:<br />
@base = QSqlDatabase::addDatabase("QODBC");</p>
<p dir="auto">QSettings sets("FlowModel","Settings");<br />
currentBase = sets.value("currentBase").toString();</p>
<pre><code>base.setHostName("localhost");
base.setDatabaseName(QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1").arg(currentBase));
</code></pre>
<p dir="auto">if(base.open())<br />
QMessageBox::information(0,"Все отлично!","База данных открыта","Ок");</p>
<p dir="auto">else<br />
QMessageBox::information(0,"Все не ахти!",base.lastError().text(),"Ок");</p>
<p dir="auto">QSqlQuery queryMaterials("SELECT * FROM Материал",base);</p>
<p dir="auto">int fieldNo = queryMaterials.record().indexOf("Название");</p>
<p dir="auto">int i = 0;</p>
<p dir="auto">while (queryMaterials.next()) {</p>
<p dir="auto">comboBox-&gt;insertItem(i++,queryMaterials.value(fieldNo).toString());</p>
<pre><code> }
</code></pre>
<p dir="auto">queryMaterials.clear();@<br />
It works correctly and combo box takes all materials from Database;<br />
But next is going this code:<br />
@QSqlQuery queryInfo("SELECT * FROM Свойства_материала WHERE Название='Вода'",base);</p>
<p dir="auto">fieldNo = queryInfo.record().indexOf("P");</p>
<p dir="auto">pLine-&gt;setText(queryInfo.value(fieldNo).toString());@<br />
And it didn't work! Query returns an empty string (""), but must be a number. I test this SQL-query in Access and there it works correct. Please help to understand what a problem i have.<br />
Thank you.</p>
]]></description><link>https://forum.qt.io/topic/20962/ms-access-and-qsqlquery</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 00:21:56 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/20962.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Oct 2012 16:51:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MS Access and QSqlQuery on Mon, 29 Oct 2012 04:44:33 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="ChrisW67" date="1351471417"]When you QSqlQuery::exec() (as the constructor does),  the newly active() query is not pointing at a valid record.  You need to call next() as the examples in the docs do.</p>
<p dir="auto">From the Detailed section of the QSqlQuery docs:</p>
<p dir="auto">bq. Successfully executed SQL statements set the query's state to active so that isActive() returns true. Otherwise the query's state is set to inactive. In either case, when executing a new SQL statement, the query is positioned on an invalid record. An active query must be navigated to a valid record (so that isValid() returns true) before values can be retrieved.<br />
[/quote]</p>
<p dir="auto">Heh, thank you very much! Now all works. I was careless :)<br />
Good luck and thanks again!</p>
]]></description><link>https://forum.qt.io/post/155648</link><guid isPermaLink="true">https://forum.qt.io/post/155648</guid><dc:creator><![CDATA[UndeadBlow]]></dc:creator><pubDate>Mon, 29 Oct 2012 04:44:33 GMT</pubDate></item><item><title><![CDATA[Reply to MS Access and QSqlQuery on Mon, 29 Oct 2012 00:43:37 GMT]]></title><description><![CDATA[<p dir="auto">When you QSqlQuery::exec() (as the constructor does),  the newly active() query is not pointing at a valid record.  You need to call next() as the examples in the docs do.</p>
<p dir="auto">From the Detailed section of the QSqlQuery docs:</p>
<p dir="auto">bq. Successfully executed SQL statements set the query's state to active so that isActive() returns true. Otherwise the query's state is set to inactive. In either case, when executing a new SQL statement, the query is positioned on an invalid record. An active query must be navigated to a valid record (so that isValid() returns true) before values can be retrieved.</p>
]]></description><link>https://forum.qt.io/post/155644</link><guid isPermaLink="true">https://forum.qt.io/post/155644</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Mon, 29 Oct 2012 00:43:37 GMT</pubDate></item><item><title><![CDATA[Reply to MS Access and QSqlQuery on Sun, 28 Oct 2012 20:16:08 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="Andre" date="1351454878"]Do you get an error back from your queryInfo? Check the <em>lastError()</em> method.[/quote]<br />
Thank you for your answer. Yes, I'm tried to use this method, but it report me nothing.<br />
I can't understand what is that... Because this table can be opened by this code:<br />
@QSqlDatabase accessBase = QSqlDatabase::addDatabase("QODBC");</p>
<p dir="auto">accessBase.setHostName("localhost");</p>
<p dir="auto">accessBase.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=D:/ИТ.mdb");</p>
<p dir="auto">if(accessBase.open())<br />
QMessageBox::information(0,"Все отлично!","База данных открыта","Ок");</p>
<p dir="auto">else<br />
QMessageBox::information(0,"Все не ахти!",accessBase.lastError().text(),"Ок");</p>
<p dir="auto">QTableView tableGhost;</p>
<p dir="auto">QSqlTableModel tableDB;</p>
<p dir="auto">QString whtpn = QInputDialog::getText(0, "Какую таблицу открыть?",<br />
"Какую таблицу открыть?");</p>
<p dir="auto">tableDB.setTable(whtpn);</p>
<p dir="auto">tableDB.select();</p>
<p dir="auto">tableDB.setEditStrategy(QSqlTableModel::OnFieldChange);</p>
<p dir="auto">tableGhost.setModel(&amp;tableDB);</p>
<p dir="auto">tableGhost.show();@<br />
And all ok. But by query no(</p>
]]></description><link>https://forum.qt.io/post/155639</link><guid isPermaLink="true">https://forum.qt.io/post/155639</guid><dc:creator><![CDATA[UndeadBlow]]></dc:creator><pubDate>Sun, 28 Oct 2012 20:16:08 GMT</pubDate></item><item><title><![CDATA[Reply to MS Access and QSqlQuery on Sun, 28 Oct 2012 20:07:58 GMT]]></title><description><![CDATA[<p dir="auto">Do you get an error back from your queryInfo? Check the <em>lastError()</em> method.</p>
]]></description><link>https://forum.qt.io/post/155636</link><guid isPermaLink="true">https://forum.qt.io/post/155636</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Sun, 28 Oct 2012 20:07:58 GMT</pubDate></item></channel></rss>