private void DeleteData(int orginId, string tableName, string dbName) { string sqlCommand = string.Format("delete from {0} where pkid = {1}", tableName, orginId); try { SqlCommandRunner.ExecuteNonQuery(new SqlCommand(sqlCommand), dbName); } catch (Exception e) { throw new ApplicationException(string.Format("{0}{1}", _Error_FilterTable, e.Message)); } }
private string FilterTheMainTable(DateTime?fromDay, DateTime?toDay, string dbName) { int allCount = SqlCommandRunner.GetTableRowCount(_MainTable, dbName); int delRowCount; string sqlCommand = DefineTheMainTableFilterCommand(fromDay, toDay); try { delRowCount = SqlCommandRunner.ExecuteNonQuery(new SqlCommand(sqlCommand), dbName); } catch (Exception e) { throw new ApplicationException(string.Format("{0}{1}", _Error_FilterTable, e.Message)); } return(string.Format("--表{0}共计:总行数{1},删减{2}行数据", _MainTable, allCount, delRowCount)); }
private void AddData(int copyId, string tableName) { string theColumnsString = MakeColumnsString(FindAllColums(_RestoreDbName, tableName), _RestoreDbName, tableName); StringBuilder addCommand = new StringBuilder(); addCommand.AppendLine(string.Format("SET IDENTITY_INSERT {0} ON", tableName)); addCommand.AppendLine(string.Format(@"insert into {0}({1}) select * from {2}.dbo.{0} where pkid = {3}", tableName, theColumnsString, _ForRestoreCopyDbName, copyId)); addCommand.AppendLine(string.Format("SET IDENTITY_INSERT {0} OFF", tableName)); try { SqlCommandRunner.ExecuteNonQuery(new SqlCommand(addCommand.ToString()), _RestoreDbName); } catch (Exception e) { throw new ApplicationException(string.Format("{0}{1},主键是:{2},原因是:{3}", _Error_AddRow, tableName, copyId, e.Message)); } }
private string FilterTheOtherTable(List <int> theRemainedMainTablePkids, string dbName, Dictionary <string, List <int> > tablesAndIds) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> theColumnn in DefineProtectedTableFkColumnName()) { int allCount = SqlCommandRunner.GetTableRowCount(theColumnn.Key, dbName); try { string theCommand = string.Format("delete from {0} where {1} not in({2})", theColumnn.Key, theColumnn.Value, MakePkidStrings(theRemainedMainTablePkids)); sb.AppendLine(string.Format("--表{0}共计:总行数{1},删减{2}行数据", theColumnn.Key, allCount, SqlCommandRunner.ExecuteNonQuery(new SqlCommand(theCommand), dbName))); tablesAndIds.Add(theColumnn.Key, FindAllPkids(theColumnn.Key, dbName)); } catch (Exception e) { throw new ApplicationException(string.Format("{0}{1}", _Error_FilterTable, e.Message)); } } return(sb.ToString()); }