• 大小: 231KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 数据库
  • 标签: Qt  数据库  

资源简介

用Qt写的连接数据库程序,并创建数据表,将txt数据导入数据库中

资源截图

代码片段和文件信息

#include 
#include ject>
#include 
QSqlQuery *query;
void  createTable()
{
    QString cmd=“CREATE TABLE RTU(num INTEGER PRIMARY KEY  identity(11)“
                “RtuName VARCHAR(12) NOT NULL“
                “TimeLabelStart VARCHAR(12) NOT NULL“
                “TimeLabelEnd VARCHAR(12) NOT NULL“
                “RareData text NOT NULL“
                “LocL1 INTEGERRxy1 INTEGER“
                “LocL2 INTEGERRxy2 INTEGER“
                “LocL3 INTEGERRxy3 INTEGER)“;
    if (query->exec(cmd))
    {
        qDebug()<<“create table success!!!“;
    }
    else
    {
        qDebug()<<“create table error“<lastError().text();
    }
}

QStringList ReadFiles()
{
    QStringList list;
    QDir *path=new QDir();
    path->setPath(“E:/DataTemp“);
    QFileInfoList FileInfoList = path->entryInfoList();
    FileInfoList.removeFirst();
    FileInfoList.removeFirst();
    for (int i=0;i    {
        QFileInfo FileInfo=FileInfoList.at(i);
        if (FileInfo.isDir())
        {
            QString tmp=FileInfo.absoluteFilePath();
            QString FileName = tmp.right(tmp.size() - tmp.lastIndexOf(‘/‘)-1);
            list<        }
    }
    return list;
}

void InsertData()
{
    QStringList fileList=ReadFiles();
    for (int i=0;i    {
        QDateTime timeStart=QDateTime().fromString(fileList.at(i)+“0000““yyyyMMddhhmm“);
        QDateTime timeOver=QDateTime().fromString(fileList.at(i)+“2359““yyyyMMddhhmm“);
        QString URL1=“E:/DataTemp/“+fileList.at(i)+“/RTU01_01/“;
        QString URL2=“E:/DataTemp/“+fileList.at(i)+“/RTU01_02/“;
        QString filename1;
        QString updatadndata;
        while(timeOver.secsTo(timeStart)<0)
        {
            filename1=timeStart.toString(“yyyyMMddhhmm“)+“.txt“;
            QFile file1(URL1+filename1);
            QFile file2(URL2+filename1);
            qDebug()<
            if(file1.exists() && file2.exists())
            {
                if(file1.open(QFile::ReadOnly) && file2.open(QFile::ReadOnly))
                {
                    QTextStream in1(&file1);
                    QTextStream in2(&file2);
                    updata.clear();
                    dndata.clear();
                    while(!in1.atEnd())
                    {
                        updata=updata.append(in1.readLine());
                    }
                    while(!in2.atEnd())
                    {
                        dndata=dndata.append(in2.readLine());
                    }
                    file1.close();
                    file2.close();
                }
                QString timeLabelStart=filename1.left(12);
                QString  timeLabelEnd=timeLabelStart;
                for (int i=10;i<30;i=i+2)
                {
                    QString RTUName1=“RTU01_“+QString(“%1“).arg(i);
                    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        318  2012-02-20 10:15  CreateSqlServerDB\CreateSqlServerDB.pro

     文件     527342  2012-02-21 10:57  CreateSqlServerDB\debug\CreateSqlServerDB.exe

     文件     314240  2012-02-21 10:57  CreateSqlServerDB\debug\main.o

     文件       5007  2012-02-21 10:57  CreateSqlServerDB\main.cpp

     目录          0  2012-02-21 10:57  CreateSqlServerDB\debug

     目录          0  2012-02-20 10:54  CreateSqlServerDB\release

     目录          0  2013-01-27 10:40  CreateSqlServerDB

----------- ---------  ---------- -----  ----

               846907                    7


评论

共有 条评论