public static bool InsertRows(List <DataRow> rows, bool addRowsToTable)
 {
     if (DataBaseConnector.InserteRecords(rows))
     {
         if (addRowsToTable)
         {
             foreach (var row in rows)
             {
                 row.Table.Rows.Add(row);
             }
         }
         return(true);
     }
     return(false);
 }
        public static string InsertTableRows(DataTable sourceTable, string destTableName)
        {
            string    message   = string.Empty;
            DataTable destTable = GetTable(destTableName);
            var       newRows   = new List <DataRow>(sourceTable.Rows.Count);
            var       rowId     = GetNewId(destTableName);

            foreach (DataRow row in sourceTable.Rows)
            {
                try {
                    var decodeRow = KeyValueSwitch.DecodeRow(row, destTable);
                    if (destTable.Columns.Contains("ID"))
                    {
                        decodeRow["ID"] = rowId++;
                    }
                    else
                    {
                        SetNewId(destTableName, decodeRow);
                    }
                    newRows.Add(decodeRow);
                    destTable.Rows.Add(decodeRow);
                } catch (Exception ex) {
                    message += "\n" + ex.Message + " Строка в файле " + sourceTable.Rows.IndexOf(row);
                }
            }
            if (string.IsNullOrEmpty(message))
            {
                try {
                    DataBaseConnector.InserteRecords(newRows);
                    foreach (var row in newRows)
                    {
                        AddRowToTable(destTable, row);
                    }
                } catch (Exception ex) {
                }
            }
            else
            {
                foreach (var row in newRows)
                {
                    destTable.Rows.Remove(row);
                }
            }
            return(message);
        }