StrataFrame Forum

Using a BusinessLayer to fill a specific BO

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

By Greg McGuffey - 10/28/2007

Can I use a generic BusinessLayer to fill a specific BO if the datatable in the BusinessLayer is filled in a way that the BO can handle?



I.e. I have a CustomersBO with these fields:



CustID

CustName



Then I instantiate a BusinessLayer and use FillDataTable with SQL like this:



Dim bo As New BusinessLayer()

bo.FillDataTable("Select CustID, CustName From Customers")




Can I then do:



CustomersBO.CopyDataFrom(bo,ClearAndFillFromCompleteTable)
By Greg McGuffey - 10/29/2007

bump...
By Paul Chase - 10/29/2007

Greg,

I'm not sure what you a trying to do but why not something like this

Dim loTable As Data.DataTable

Fill the Data Table

loTable = MicroFour.StrataFrame.Data.DataBasics.DataSources("").GetDataTable("Select CustID, CustName From Customers", Nothing)

'Not sure if you need to clear it

CustomerBo.CurrentDataTable.Clear()

'Load the data from the Table

CustomerBo.CurrentDataTable.Load(loTable.CreateDataReader, Data.LoadOption.OverwriteChanges)

By Greg McGuffey - 10/29/2007

That could work...and it saves the extra overhead of the BO. I'll try that. Thanks Paul!
By StrataFrame Team - 10/30/2007

Paul's option is a good one and it does save the overhead of instantiating another business object.

But, a business object can store data that does not match it's strong-typed properties, so you could really use any business object and fill it.  Just don't go trying to access those strong-typed properties that don't have a backing field, or you'll get a nice exception Wink

Using Paul's option is cleaner.

Oh, and there's also the CopyDataFrom() and MergeDataFrom() overloads that accept DataTable parameters if you won't want to use the Load method directly on the CurrentDataTable.

By Greg McGuffey - 10/30/2007

Thanks for the reply Ben. It is all making sense now. I haven't done much at the data layer directly, so I appreciate Paul's comments a lot!