StrataFrame Forum

CopyDataFrom does not work

http://forum.strataframe.net/Topic25505.aspx

By Rainer Kempf, RK - 1/7/2010

Hi,

I have a problem with CopyDataFrom. I have some DataSet and DataTable filled with data. Then I want to export this data through BusinessObject to SQL Server. I have correct data in the BO.CurrentDataTable, but after Save() I have no data on SQLServer. Save operation returns success.
I have a next code

Dim
loBBDS As BestbuyImportDataSet = CType(toDS, BestbuyImportDataSet)
If loBBDS.vbestbuy.Count > 0 Then
Dim loVBestbuyBO As MKS.GoliathNet.BusinessObjects.ErpBestbuy.vbestbuyBO = New vbestbuyBO
loVBestbuyBO.mmks_deletemanufacturerartikels(_pmks_businessObject.driver_manufacturer_pk_id)

loVBestbuyBO.CopyDataFrom(loBBDS.vbestbuy, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)
If loVBestbuyBO.IsDirty Then
MessageBox.Show("IsDirty")
End If

If loVBestbuyBO.Save() = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then
MessageBox.Show("SaveSuccess")
End If

So step by step.
loBBDS.vbestbuy.count has 6000 records
After CopyDataFrom - businessObject CurrentDataTable has also 6000 records
IsDirty - FALSE!!!
Save() is Success! And NO DATA ON SQL SERVER!

Any help!
Thanks!

By Trent L. Taylor - 1/8/2010

This is not a bug as is designed this way. You are trying to perform a CopyDataFrom and then performing a save immediately afterward assuming that the BO will copy the data in as dirty...it doesn't. The CopyDataFrom WILL NOT COME IN AS DIRTY (as you have discovered). So if you want to move data into the BO then save it from a data table, either enumerate the rows in the inbound data table and manually add each row, or after you have performed the CopyDataFrom, enumerate the rows in the CurrentDataTable and set the row state of each row to Modified and that should make the records dirty.



One major issue of note here if you take the second approach would be primary keys. If you are bringing data into the BO that already has a primary key set, then you will have to account for this when the record is being saved (one of the several reasons the CopyDataFrom comes in as clean data). That is why in this example, I would take the first approach and manually add the records into the BO so that the BO logic can then work as it is designed to save the PKs (by creating new ones if necessary), etc. as they would if they were new records. On the flip hand side, if you want to keep the PKs the same, then you will need to set the PrimaryKeyIsUpdatable property on the BO to true as well as the PrimaryKeyIsAutoIncremented property to false. If you are using a SPROC on the INSERT, then you will most likely want to set the CRUD property on the BO InsertUsingStoredProcedure to false as well to prevent any PK issues. One last thought is that you will need to execute a SPROC prior to the save allowing PKs to be inserted (SET IDENTITY INSERT ON).