Ejemplo n.º 1
0
        public void Import(DataFile file)
        {
            if (!context.DatabaseExists(file.database))
            {
                context.CreateDatabase(file.database);
            }

            DataSet dataSet = new DataSet(file.database);

            dataSet.ReadXml(file.path);
            DataTableCollection tables = dataSet.Tables;

            for (int i = 0; i < tables.Count; i++)
            {
                DataTable table       = tables[i];
                string[]  columnNames = new string[table.Columns.Count];

                for (int j = 0; j < table.Columns.Count; j++)
                {
                    columnNames[j] = table.Columns[j].ColumnName;
                }

                string query = SQLQueryGenerator.GetCreateTableQuery(table.TableName, columnNames);
                context.ExecuteNonQuery(query);
            }
        }
Ejemplo n.º 2
0
        private void CreateDatabaseTable(DataFile file, DataTable data, SqlBulkCopy bulkCopy)
        {
            DataColumnCollection columns = data.Columns;

            string[] columnNames = new string[columns.Count];

            for (int i = 0; i < columns.Count; i++)
            {
                string columnName = columnNames[i] = columns[i].ColumnName;
                bulkCopy.ColumnMappings.Add(columnName, columnName);
            }

            string createTableQuery = SQLQueryGenerator.GetCreateTableQuery(file.fileName, columnNames);

            context.ExecuteNonQuery(createTableQuery);
            context.Refresh();

            bulkCopy.DestinationTableName = SQLQueryGenerator.EncloseInBrackets(file.fileName);
            bulkCopy.WriteToServer(data);
        }