StrataFrame Forum

How do I use CopyDataFrom to remove duplicates from BO populated by Browse Dialog?

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

By Marcia G Akins - 10/21/2008

Hi All.

I created a view that is a three table join so that I can use this view to populate my BO using the BrowseDialog. The problem is that this may result in multiple records in the BO that gets populated. I do not want the "real" BO being handled in my form to contain these mutliple records. So how can I use CopyDataFrom to ensure that I get only the DISTINCT records for my "real" BO?

TIA.

Marcia

By Ivan George Borges - 10/21/2008

Hi Marcia.

Maybe you could drop another instance of your BO in your form and use it as your BrowseDialog's BusinessObjectToPopulate. Then in the BrowseDialogClosed method, if a OK was pressed by the user, you could filter your populated BO as needed and use the CopyDataFrom to copy the records to your primary BO.

As for how to filter the duplicated records, you could add a new Column to your BO for that purpose.

    Private Sub MyBO_CurrentDataTableInitialized() Handles MyBO.CurrentDataTableInitialized
        If Me.CurrentDataTable.Columns.Contains("myb_Duplicated") = False Then
            Me.CurrentDataTable.Columns.Add("myb_Duplicated", System.Type.GetType("System.Boolean"))
        End If
    End Sub

(You probably need to create the custom property for that column too)

Then you could go through all your records testing for duplicated ones, and flaging then as so. Filter on that flag before the CopyDataFrom.

Hope I could make some sense... Wink

By Marcia G Akins - 10/21/2008

Ivan George Borges (10/21/2008)
Hi Marcia.

As for how to filter the duplicated records, you could add a new Column to your BO for that purpose.

    Private Sub MyBO_CurrentDataTableInitialized() Handles MyBO.CurrentDataTableInitialized
        If Me.CurrentDataTable.Columns.Contains("myb_Duplicated") = False Then
            Me.CurrentDataTable.Columns.Add("myb_Duplicated", System.Type.GetType("System.Boolean"))
        End If
    End Sub

(You probably need to create the custom property for that column too)

Then you could go through all your records testing for duplicated ones, and flaging then as so. Filter on that flag before the CopyDataFrom.

Hope I could make some sense... Wink

Hi Ivan.

Thanks so much for the quick response. I wish I could say that this makes sense to me, but unfortunately, it doesn't Smile

I have used the CopyDataFrom method before when there was no chance of pulling back duplicate records. Basically, I am after a way to do a "SELECT DISTINCT" from the BrowseDialog BO into the "real" BO.

By Paul Chase - 10/21/2008

Hi Marcia,

You can do something like this to copy only distinct rows from one bo to another.

Me.RealBizObject.CopyDataFrom(Me.BrowseBizobject.CurrentDataTable.DefaultView.ToTable(True, New String() {"DistictColumn-ColumnName"}), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

Hope that helps

Paul

 

By Marcia G Akins - 10/21/2008

Paul Chase (10/21/2008)
Hi Marcia,

You can do something like this to copy only distinct rows from one bo to another.

Me.RealBizObject.CopyDataFrom(Me.BrowseBizobject.CurrentDataTable.DefaultView.ToTable(True, New String() {"DistictColumn-ColumnName"}), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

Hope that helps

Hi Paul.

Thanks - that does help. Now, if I use that syntax (converted to C#, of course Wink), will it use that column to determin which ones are the duplicates but copy all the other columns?

By Paul Chase - 10/21/2008

Thanks - that does help. Now, if I use that syntax (converted to C#, of course Wink), will it use that column to determin which ones are the duplicates but copy all the other columns?

Hiya Marcia

It works like Select Distinct ColumnName(s) fromTableName.

You will need to add the columns just as you would with a regular select distinct statement

So something like

Me.RealBizObject.CopyDataFrom(Me.BrowseBizobject.CurrentDataTable.DefaultView.ToTable(
True, New String() {"Cus_pk","cus_Name","Cus_anotherfld"}), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

=

Select Distinct cus_pk,cus_name,Cus_anotherfld from sometable.

 BigGrin

By Marcia G Akins - 10/21/2008

Paul Chase (10/21/2008)

It works like Select Distinct ColumnName(s) fromTableName.

Perfect - thanks for the explanation Smile Now I know why my code was blowing up with a "column active_flg does not belong to table client" BigGrin

By Marcia G Akins - 10/21/2008

Hi Paul.

I just wanted to thank you so much for your great advice. Once you explained how this worked, everything worked out great.

Thanks again for staying with a newbie like me Smile

By Paul Chase - 10/21/2008

Marcia

I'm glad I was able to help!! Wink

Paul

By Ivan George Borges - 10/21/2008

Yep, that was a lot eaiser! w00t
By Trent L. Taylor - 10/22/2008

Good answer, Paul. Smile