Esempio n. 1
0
        private void startDataReader()
        {
            Db.DriverEnum dbDriver=databaseDriver();
            Db db=new Db(dbDriver);
            string qryReader, qryRowCount, fileName, fileBaseName, filePath, fileNameWithPath;
            OdbcCommand cmd = new OdbcCommand();
            int rowCount, colCount;
            OdbcDataReader reader;

            rowCount=colCount=0;
            qryReader=qryRowCount=fileName=fileBaseName=filePath=fileNameWithPath="";

            fileNameWithPath = this.openFileDialog.FileName;
            fileName = Fcn.FileName(fileNameWithPath);
            fileBaseName = Fcn.FileBaseName(fileName);
            filePath = Fcn.FilePath(fileNameWithPath);
            switch (dbDriver)
            {
                case Db.DriverEnum.DBase:
                     db.Connect("MaxBufferSize=2048;DSN=dBASE Files;PageTimeout=5;DefaultDir=" + filePath +
                         ";DBQ=" + filePath + ";DriverId=533");
              			     qryRowCount="Select count(*) from " + fileBaseName;
                     qryReader="Select * from " + fileBaseName;
                break;
                case Db.DriverEnum.CSV:
                     db.Connect("MaxBufferSize=2048;FIL=text;DSN=CSV;PageTimeout=5;DefaultDir=" + filePath +
                        ";DBQ=" + filePath + ";DriverId=27");
                     qryRowCount="Select count(*) from " + fileName;
                     qryReader="Select * from " + fileName;
                break;
                case Db.DriverEnum.Excel:
                    db.Connect("MaxBufferSize=2048;DSN=Excel Files;PageTimeout=5;DefaultDir=" + filePath +
                    ";DBQ=" + fileNameWithPath + ";DriverId=790");
                    qryRowCount="Select count(*) from [Sheet1$]";
                    qryReader="Select * from [Sheet1$]";
                    break;
            }
            cmd = new OdbcCommand(qryRowCount, db.Con);
            Def= (int) cmd.ExecuteScalar();
            cmd = new OdbcCommand(qryReader, db.Con);
            reader = cmd.ExecuteReader();
            colCount = reader.FieldCount;
            FillPhysicalTable(reader, colCount, rowCount);
            db.Close();
        }