Exemplo n.º 1
0
        void FilePathButtonClick(object sender, EventArgs e)
        {
            var location = SetFolderLocation();
            if (location == "") return;

            foreach (var fileName in FlatFileReader.GetAllFileNames(location))
            {
                var gStandardReader = new GStandardSchemaReader(location, fileName);
                var name = fileName + "_" + gStandardReader.GetName();
                var columnInfos = gStandardReader.GetFlatFileColumnInfo();
                using (var sqlBulkImport = new SqlBulkImport("Server=localhost;Database=GStandDb;Trusted_Connection=True;"))
                {
                    var dt = sqlBulkImport.CreateTable(name);
                    sqlBulkImport.CreateColumns(dt, columnInfos);
                    FlatFileReader.ReadFlatFileInToDataset(Path.Combine(location, fileName), dt, name, columnInfos);
                    sqlBulkImport.ImportTable(dt, name);
                }
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                this.folderLocationLabel.Text = folderBrowserDialog.SelectedPath;
            }

            string tempPath = folderBrowserDialog.SelectedPath;

            foreach (string fileName in FlatFileReader.GetAllFileNames(tempPath))
            {
                var gStandardReader = new GStandardSchemaReader(tempPath, fileName);
                var name = gStandardReader.GetName();
                var columnInfos = gStandardReader.GetFlatFileColumnInfo();
                using (var sqlBulkImport = new SqlBulkImport("Server=localhost;Database=testdb2;Trusted_Connection=True;"))
                {
                    var dt = sqlBulkImport.CreateTable(name);
                    sqlBulkImport.CreateColumns(dt, columnInfos);
                    FlatFileReader.ReadFlatFileInToDataset(Path.Combine(tempPath, fileName), dt, name, columnInfos);
                    sqlBulkImport.ImportTable(dt, name);
                }
            }
        }