public override void saveRows(DataTable dt, DataRow[] dr, IDbTransaction tran) { try { //using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tran.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)tran)) //{ // var rows = dr.Where(r => r.RowState == DataRowState.Added).ToArray(); // bulkCopy.DestinationTableName = dt.TableName; // if (dt.PrimaryKey.Cast<DataColumn>().Count(dc => dc.AutoIncrement) == 0) // { // foreach (DataColumn col in dt.Columns) // bulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(col.ColumnName, col.ColumnName)); // bulkCopy.WriteToServer(rows); // rows.ToList().ForEach(r => r.AcceptChanges()); // } //} using (SqlDataAdapter da = new SqlDataAdapter(new SqlCommand("", (SqlConnection)tran.Connection, (SqlTransaction)tran))) { da.InsertCommand = SqlSyntax.CreateInsertCommand(dt); da.InsertCommand.Connection = (SqlConnection)tran.Connection; da.InsertCommand.Transaction = (SqlTransaction)tran; da.UpdateCommand = SqlSyntax.CreateUpdateCommand(dt); da.UpdateCommand.Connection = (SqlConnection)tran.Connection; da.UpdateCommand.Transaction = (SqlTransaction)tran; da.DeleteCommand = SqlSyntax.CreateDeleteCommand(dt); da.DeleteCommand.Connection = (SqlConnection)tran.Connection; da.DeleteCommand.Transaction = (SqlTransaction)tran; da.Update(dr); } } catch (Exception e) { Trace.WriteLine("Save error."); Trace.WriteLine(e); Trace.WriteLine(dt.TableName); dr.ToList().ForEach(r => { if (r.RowState == DataRowState.Added || r.RowState == DataRowState.Modified) { dt.Columns.Cast<DataColumn>().ToList().ForEach(c => { Trace.WriteLine(c.ColumnName); Trace.WriteLine(r[c].ToString()); }); } else if (r.RowState == DataRowState.Deleted) Trace.WriteLine("Deleting row..."); }); throw; } }