Sorry i think if Szie() is -1 then next() and value() will by not work. Thx for help.
Is other way to check how meny record have query ???
I do someting like that, it work's but is not good way.
void MainWindow::on_pushButtonGetUsers_clicked()
{
query.exec("SELECT Knt_Kod, Knt_Ulica, Knt_NrDomu, Knt_Miasto, Knt_KodPocztowy, Knt_Poczta, Knt_Pesel FROM CDN.Kontrahenci");
query.next();
if(!query.value(0).toString().isEmpty())
{
ui->tableWidget->setRowCount(1);
addRecordToTable(&query, 0);
query.next();
int row=2;
while(!query.value(0).toString().isEmpty())
{
ui->tableWidget->setRowCount(row);
addRecordToTable(&query, row-1);
row++;
query.next();
}
}
}
void MainWindow::on_pushButtonGetUsers_clicked()
{
QSqlQuery query(db);
query.exec("SELECT Knt_Kod, Knt_Ulica, Knt_NrDomu, Knt_Miasto, Knt_KodPocztowy, Knt_Poczta, Knt_Pesel FROM CDN.Kontrahenci");
query.next();
if(!query.value(0).toString().isEmpty())
{
ui->tableWidget->setRowCount(1);
addRecordToTable(&query, 0);
query.next();
int row=2;
while(!query.value(0).toString().isEmpty())
{
ui->tableWidget->setRowCount(row);
addRecordToTable(&query, row-1);
row++;
query.next();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks