public virtual bool SaveOnly() { bool saved = false; RowAdapter d = GetPersistentRow(); foreach (DataRow dataRow in dataTable.Rows) { if (dataRow.RowState != DataRowState.Deleted) { d.UpdateColumnValue(dataRow); if (DataRowChangedHandler != null) { d.RowChanged += DataRowChangedHandler; } if (ValueChangedHandler != null) { d.ValueChangedHandler = ValueChangedHandler; } if (dataRow.RowState != DataRowState.Unchanged) { saved = d.Save(); } } else { dataRow.RejectChanges(); d.UpdateColumnValue(dataRow); if (DataRowChangedHandler != null) { d.RowChanged += DataRowChangedHandler; } if (ValueChangedHandler != null) { d.ValueChangedHandler = ValueChangedHandler; } d.Delete(); dataRow.Delete(); } } return(saved); }
public virtual bool Save(Selector columnNames, RowChangedHandler rowHandler, ValueChangedHandler columnHandler) { if (dataTable == null || dataTable.Rows.Count == 0) { return(false); } //update this.dataTable // this.AcceptChanges(); objectPermission = ObjectPermission.DenyUpdateObject; RowAdapter d = this.NewSqlRow(columnNames); d.RowChanged += RowChanged; if (rowHandler != null) { d.RowChanged += rowHandler; } if (columnHandler != null) { d.ValueChangedHandler = columnHandler; } else { d.ValueChangedHandler = ValueChanged; } int count = 0; foreach (DataRow dataRow in dataTable.Rows) { BeforeSave(dataRow); if (dataRow.RowState != DataRowState.Deleted) { if (dataRow.RowState != DataRowState.Unchanged) { d.CopyFrom(dataRow); d.Fill(); d.Save(); if (dataRow.RowState == DataRowState.Added) //in case of existing identity columns { d.CopyTo(dataRow); UpdateObject(dataRow); } //slow version //T t = this[dataRow]; //t.Save(d); count++; } } else { dataRow.RejectChanges(); d.CopyFrom(dataRow); d.Fill(); d.Delete(); //slow version //T t = this[dataRow]; //t.Delete(); dataRow.Delete(); } AfterSave(dataRow); } dataTable.AcceptChanges(); objectPermission = ObjectPermission.AllowUpdateObject; return(true); }