override public ImportResult[] ImportData(ImportStatement[] statements) { List <ImportResult> importResults = new List <ImportResult>(); string connectionString = ConnectionStringMaker.SQLServerConnectionString(config.ConnectionSetup); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Open(); foreach (ImportStatement s in statements) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = s.SqlStatement; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection; try { int rowsAffected = cmd.ExecuteNonQuery(); importResults.Add(new SuccesfulImport(s, rowsAffected)); } catch (SqlException e) { importResults.Add(new UnsuccesfulImport(s, e.Message)); } } } return(importResults.ToArray()); }
public override ImportResult ImportData(ImportStatement statement) { string connectionString = ConnectionStringMaker.SQLServerConnectionString(config.ConnectionSetup); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = statement.SqlStatement; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection; try { int rowsAffected = cmd.ExecuteNonQuery(); return(new SuccesfulImport(statement, rowsAffected)); } catch (SqlException e) { return(new UnsuccesfulImport(statement, e.Message)); } } }