Пример #1
0
 private static void WriteDBWithTable(System.Data.DataTable dt, string tablename)
 {
     if (dt.Rows.Count > 0)
     {
         var targetcon = DBUtility.GetLocalConnector();
         using (SqlBulkCopy bulkCopy = new SqlBulkCopy(targetcon))
         {
             bulkCopy.DestinationTableName = tablename;
             try
             {
                 for (int i = 1; i < dt.Columns.Count; i++)
                 {
                     bulkCopy.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);
                 }
                 bulkCopy.WriteToServer(dt);
                 dt.Clear();
             }
             catch (Exception ex) { }
         } //end using
         DBUtility.CloseConnector(targetcon);
     }     //end if
 }