By Felix M Avendano - 3/6/2012
I did this in a button, and it doesn't save the data to the table, Ive double checked and after the save command both bo's are populated, ant the msgbox says localidades grabadas, but it's false, ir does nothing. Here is the script.
Dim vventrianlocalidadesyzonas As New BOventrianlocalidadesyzonas Dim vlocalidadesyzonas As New BOLocalidadesyzonas vventrianlocalidadesyzonas.DataSourceKey = "Webconn" vlocalidadesyzonas.PrimaryKeyIsAutoIncremented = True vlocalidadesyzonas.PrimaryKeyIsUpdatable = True
vventrianlocalidadesyzonas.FillAll()
vlocalidadesyzonas.CopyDataFrom(vventrianlocalidadesyzonas, BusinessCloneDataType.ClearAndFillFromDefaultView)
If vlocalidadesyzonas.Save() = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then MsgBox("Localidades Grabadas!") Else MsgBox("Un error ocurrió durante la grabación...") End If
|
By Edhy Rijo - 3/6/2012
Hi Felix,
In your sample, you are not making any changes to the RowState of the copied BO. The BO.CopyDataFrom() method will not update the RowState of the rows copied, if you want the RowState changed, then you have to enumerate the BO and change each row to the RowState you want. Here is some code that illustrate the solution from one of my projects, pay attention to the comments in the code:
If Me.BizTransactionItemsStock_TEMP_ForNewRecords.Count > 0 Then '-- Reset filter condition to show all selected cards. Me.BizTransactionItemsStock1.Filter = ""
'-- Copy new records to the main Stock BO Me.BizTransactionItemsStock1.CopyDataFrom(Me.BizTransactionItemsStock_TEMP_ForNewRecords, BusinessCloneDataType.AppendDataToTableFromDefaultView) Me.BizTransactionItemsStock_TEMP_ForNewRecords.Clear()
'-- Since these are new records and the BO.CopyDataFrom method will ' set the RowState to Unchanged, then force the RowState ' as Added to guarantee the record will be added to the table when saved. Me.BizTransactionItemsStock1.Filter = "PK_TransactionItemsStock < 0" Dim newTempPKValue As Integer = 0 For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable() '-- ER 11/23/2010, when doing a CopyDataFrom the new PK value may be -1 and this may already exist in the uncommitted BO Me.BizTransactionItemsStock1 ' we need to make sure that if the -1 PK value exist, to reassign the PK so they are unique to be used later when editing the record and the listview ' could auto navigate properly to the listviewitem.Tag newTempPKValue += -1 If StockBO.CurrentRow.RowState <> Data.DataRowState.Added Then StockBO.CurrentRow.SetAdded() StockBO.PK_TransactionItemsStock = newTempPKValue End If Next End If
|
|