[Qt-interest] Qsql database
Yuvaraj R
yuvaraj at ongobiz.com
Wed Sep 23 22:51:18 CEST 2009
Hi All
I added some details to my database..
once i close the application and again open means ..nothing it displaying..
My Code is
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTableView>
#include<QMessageBox>
#include <QSqlQuery>
#include<QDebug>
#include <QSqlRecord>
#include <QInputDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
create_tables();
QSqlQuery query("SELECT * FROM employee");
QSqlRecord rec = query.record();
int a = rec.indexOf("name");
while(query.next())
{
qDebug() << query.value(a).toString();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::create_tables()
{
query.exec("create table employee(id int primary key, name varchar(20), city
int, country int)");
query.exec("insert into employee values(1, 'Espen', 5000, 47)");
query.exec("insert into employee values(2, 'Harald', 80000, 49)");
query.exec("insert into employee values(3, 'Sam', 100, 1)");
}
void MainWindow::on_pushButton_clicked()
{
bool ok;
QStringList ongo;
QString text = QInputDialog::getText(this,"MaxxTel","Enter Buddy
name(Eg:john)",QLineEdit::Normal,"",&ok);;
if (ok && !text.isEmpty())
{
yuvaraj =text.split(",");
}
query.exec("insert into employee values('4', 'OngoBiz','100000','50')");
QSqlQuery query("SELECT * FROM employee");
QSqlRecord rec = query.record();
int a = rec.indexOf("name");
while(query.next())
{
qDebug() << query.value(a).toString();
}
}
why once we close application and again relogin means,it is not displaying
previously stored details.
Please help me
Thanks
Yuvaraj R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090924/fb820579/attachment.html
More information about the Qt-interest-old
mailing list