14 Şubat 2018 Çarşamba

Connect to Sql Server from Qt

// server    :  192.168.0.251\\SQLEXPRESS,507  
   port      :  507 
   database  : gpslgd
   Uid       : Takip
   Password  :



 QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("DRIVER={SQL Server};Server=192.168.0.251\\SQLEXPRESS,507;Database=gpslogd;
                       Uid=Takip;Pwd=1223;WSID=.");
if(db.open())
{

    QSqlQueryModel *model = new QSqlQueryModel;
    QString query = "select * from states";
    model->setQuery(query, db);
    qDebug()<<  model->record(2).value(0).toString();
    qDebug()<<  model->record(2).value(1).toString();
    qDebug()<<  model->record(2).value(2).toString();
    qDebug()<<  model->record(2).value(3).toString();
    qDebug()<<  model->record(2).value(4).toString();
    qDebug()<<  model->record(2).value(5).toString();
    qDebug()<<  model->record(2).value(6).toString();
    qDebug()<<  model->record(2).value(7).toString();
    qDebug()<<  model->record(2).value(8).toString();
    qDebug()<<  model->record(2).value(9).toString();
    qDebug()<<  model->record(2).value(10).toString();
    qDebug()<<  model->record(2).value(11).toString();
    qDebug()<<  model->record(2).value(12).toString();

}
else
{
    qDebug()<<"not succes ";

}
Share: