#include <QtCore/QCoreApplication>#include "QSqlDatabase"#include "QSqlQuery"#include "QSqlError"#include "QtCore"#include "QTextStream"#include "QFile"int main(){ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("Windows-1251")); QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251")); QSqlDatabase my_db = QSqlDatabase::addDatabase("QMYSQL"); my_db.setHostName("192.168.1.223"); my_db.setDatabaseName("develop"); my_db.setUserName("1c"); my_db.setPassword("1c"); my_db.open(); if (!my_db.isOpen()) { qDebug() << "Bd is not open" << my_db.lastError().text() ; return 0; } QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=d:\\7n.mdb"); db.open(); if (!db.open()) { qDebug() << db.lastError().text(); } QSqlQuery q,m; q.exec("SELECT mcod,tf_okato,c_ogrn,m_names,m_namesf,post_id,adres,fam_gv,im_gv,ot_gv,fam_buh,im_buh,ot_buh,tel,fax,e_mail,date_b,date_e FROM tlpu"); QString SQL; QFile file("asf.txt"); QTextStream out(&file); file.open(QIODevice::WriteOnly | QIODevice::Text); int i = 0; while (q.next()) { SQL = QString("INSERT INTO 7n_lpu (mcode,okato,ogrn,name,name_full,post_id,adres,fam_gv,im_gv,otch_gv,fam_buh,im_buh,otch_buh,tel,fax,e_mail,date_b,date_e) VALUES ('%1','%2','%3','%4','%5','%6','%7','%8','%9','%10','%11','%12','%13','%14','%15','%16','%17','%18')") .arg(q.value(0).toString().trimmed()) .arg(q.value(1).toString().trimmed()) .arg(q.value(2).toString().trimmed()) .arg(q.value(3).toString().trimmed()) .arg(q.value(4).toString().trimmed()) .arg(q.value(5).toString().trimmed()) .arg(q.value(6).toString().trimmed()) .arg(q.value(7).toString().trimmed()) .arg(q.value(8).toString().trimmed()) .arg(q.value(9).toString().trimmed()) .arg(q.value(10).toString().trimmed()) .arg(q.value(11).toString().trimmed()) .arg(q.value(12).toString().trimmed()) .arg(q.value(13).toString().trimmed()) .arg(q.value(14).toString().trimmed()) .arg(q.value(15).toString().trimmed()) .arg(q.value(16).toString().trimmed()) .arg(q.value(17).toString().trimmed()); m.exec(SQL); } }
????????????????????????????????? ?????????????? ?????????????
#include <QtCore/QCoreApplication>#include "QSqlDatabase"#include "QSqlQuery"#include "QSqlError"#include "QtCore"#include "QTextStream"#include "QFile"int main(){ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("Windows-1251")); QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251")); QSqlDatabase my_db = QSqlDatabase::addDatabase("QMYSQL", "mysql_db"); my_db.setHostName("192.168.1.223"); my_db.setDatabaseName("develop"); my_db.setUserName("1c"); my_db.setPassword("1c"); my_db.open(); my_db.exec("SET NAMES cp1251"); if (!my_db.isOpen()) { qDebug() << "Bd is not open" << my_db.lastError().text() ; return 0; } QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "access_db"); db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=d:\\7n.mdb"); db.open(); if (!db.open()) { qDebug() << db.lastError().text(); } QSqlQuery q(db), m(my_db); q.exec("SELECT mcod,tf_okato,c_ogrn,m_names,m_namesf,post_id,adres,fam_gv,im_gv,ot_gv,fam_buh,im_buh,ot_buh,tel,fax,e_mail,date_b,date_e FROM tlpu"); QString SQL; QFile file("asf.txt"); QTextStream out(&file); file.open(QIODevice::WriteOnly | QIODevice::Text); int i = 0; while (q.next()) { SQL = QString("INSERT INTO 7n_lpu (mcode,okato,ogrn,name,name_full,post_id,adres,fam_gv,im_gv,otch_gv,fam_buh,im_buh,otch_buh,tel,fax,e_mail,date_b,date_e) VALUES ('%1','%2','%3','%4','%5','%6','%7','%8','%9','%10','%11','%12','%13','%14','%15','%16','%17','%18')") .arg(q.value(0).toString().trimmed()) .arg(q.value(1).toString().trimmed()) .arg(q.value(2).toString().trimmed()) .arg(q.value(3).toString().trimmed()) .arg(q.value(4).toString().trimmed()) .arg(q.value(5).toString().trimmed()) .arg(q.value(6).toString().trimmed()) .arg(q.value(7).toString().trimmed()) .arg(q.value(8).toString().trimmed()) .arg(q.value(9).toString().trimmed()) .arg(q.value(10).toString().trimmed()) .arg(q.value(11).toString().trimmed()) .arg(q.value(12).toString().trimmed()) .arg(q.value(13).toString().trimmed()) .arg(q.value(14).toString().trimmed()) .arg(q.value(15).toString().trimmed()) .arg(q.value(16).toString().trimmed()) .arg(q.value(17).toString().trimmed()); m.exec(SQL); } }