public bool CopyDocumentsTable(string filePath, int mode, object[] otherTables) { OleDbConnection connection = null; try { filePath = GetFullFilePath(filePath); var originalDbPath = GetDatabasePath(); File.Copy(originalDbPath, filePath, true); /////////////////////////////////////////////////////////////////////////////// connection = new OleDbConnection(_views.MainForm.GetConnectionString(filePath)); connection.Open(); /////////////////////////////////////////////////////////////////////////////// var tableExclusion = new TableExclusion { TableName = "Documents" }; /////////////////////////////////////////////////////////////////////////////// var exclusions = new List <TableExclusion> { tableExclusion }; /////////////////////////////////////////////////////////////////////////////// if (otherTables != null) { exclusions.AddRange(otherTables.Cast <string>() .Select(tableName => new TableExclusion { TableName = tableName })); } /////////////////////////////////////////////////////////////////////////////// DeleteTables(connection, exclusions); return(true); } catch (Exception ex) { OnException(ex.Message); } finally { CloseConnection(connection, true); } return(false); }
protected void DeleteRows(OleDbConnection connection, TableExclusion exclusion) { var command = connection.CreateCommand(); var cmdText = String.Format("DELETE FROM {0}", exclusion.TableName); cmdText += " WHERE "; var where = String.Empty; foreach (var condition in exclusion.ColumnValueConditions) { if (!String.IsNullOrEmpty(where)) { where += " AND "; } /////////////////////////////////////////////////////////////////////////////// cmdText += condition.ColumnName + " "; var addParameter = false; switch (condition.Operator) { case ValueConditionOperator.Equals: cmdText += String.Format("= @{0}", condition.ColumnName); addParameter = true; break; case ValueConditionOperator.MoreThan: cmdText += String.Format("> @{0}", condition.ColumnName); addParameter = true; break; case ValueConditionOperator.MoreOrEqual: cmdText += String.Format(">= @{0}", condition.ColumnName); addParameter = true; break; case ValueConditionOperator.LessThan: cmdText += String.Format("< @{0}", condition.ColumnName); addParameter = true; break; case ValueConditionOperator.LessOrEqual: cmdText += String.Format("<= @{0}", condition.ColumnName); addParameter = true; break; case ValueConditionOperator.IsNull: cmdText += "IS NULL"; break; case ValueConditionOperator.IsNotNull: cmdText += "IS NOT NULL"; break; } /////////////////////////////////////////////////////////////////////////////// if (addParameter) { command.Parameters.AddWithValue("@" + condition.ColumnName, condition.Value); } command.CommandText = cmdText; command.ExecuteNonQuery(); } }