﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Adding Custom Fields To BO Datatable</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Fri, 26 Jun 2026 13:50:19 GMT</lastBuildDate><ttl>20</ttl><item><title>Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25020.aspx</link><description>I've seen a forum post on this before but can't seem to locate it.&lt;br&gt;
&lt;br&gt;
I want to add a few temporary fields to a business object's datatable on a row by row basis to store status information but can't seem to get it to work properly at runtime. I don't want to add the fields to the database table, just to the business object.&lt;br&gt;
&lt;br&gt;
Any help would be appreciated.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Tim&lt;br&gt;</description><pubDate>Thu, 29 Oct 2009 12:46:55 GMT</pubDate><dc:creator>Tim Dol</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25058.aspx</link><description>Glad you got it working!</description><pubDate>Thu, 29 Oct 2009 12:46:55 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25054.aspx</link><description>Thanks guys, your examples helped solve my problem.</description><pubDate>Thu, 29 Oct 2009 08:47:05 GMT</pubDate><dc:creator>Tim Dol</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25032.aspx</link><description>Tim,&lt;br&gt;
&lt;br&gt;
One last thing that might make life easier. You can use your query that fills the BO to make that extra column. I.e. extending the example &lt;br&gt;
&lt;br&gt;
SELECT&lt;br&gt;
    -- First three columns are all "official" columns and will be saved by the BO&lt;br&gt;
    cs_FirstName,&lt;br&gt;
    cs_LastName,&lt;br&gt;
    cs_ID,&lt;br&gt;
    -- Any number of "extra" columns can be added as needed.&lt;br&gt;
    FALSE AS cs_Processed, -- this adds a column to underlying datatable with a default value&lt;br&gt;
    0 AS cs_Status -- Example of a couple more added columns, an int and a string&lt;br&gt;
    'P' As cs_StatusDisplay&lt;br&gt;
FROM Customers&lt;br&gt;
&lt;br&gt;
Using this method, you can then use either of the methods Dustin described to access/change the data.</description><pubDate>Wed, 28 Oct 2009 10:41:56 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25027.aspx</link><description>Yep, what Edhy said :).&amp;nbsp; &lt;/P&gt;&lt;P&gt;If you explicitly don't want a strong-typed property, then you can use the methods I described in my original post, and reference bo.CurrentRow.Item("yourcolumname") to get or set it. Since it isn't explicitely defined in the BO, it won't save back to the database. If you do want to use a strong-typed property (which is generally much cleaner), then you'll want to add it to the FieldsToExcludeFromUpdate as Edhy mentioned to prevent it from saving back to the database. &lt;/P&gt;&lt;P&gt;Thanks Edhy. Sadly, the Mexican Circus got another Strong Man and weren't interested in a Bearded Lady, so I had to come back ;).</description><pubDate>Wed, 28 Oct 2009 09:28:04 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25026.aspx</link><description>Hi Tim,&lt;br&gt;
&lt;br&gt;
You can have your cs_Processed field in the table and it will be created in the BO, then you can add  cs_Processed to the BO.FieldsToExcludeFromUpdate property so it won't be updated.&lt;br&gt;
&lt;br&gt;
Or as Dustin suggested, you can have a Custom Field Property in your BO, then use it normaly as any other field, and no data will be save back since it is not binded to anything.&lt;br&gt;
&lt;br&gt;
Other suggestion is that if you allow your users to set the cs_Processed flag, then you can use a ListView with its CheckBoxes property True and then this will add a checkbox on the first column where you can check and then you can use the ListView.CheckedItems.Count &gt; 0 to see which one have been checked and process your records.</description><pubDate>Wed, 28 Oct 2009 09:00:23 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25025.aspx</link><description>Dustin,&lt;br&gt;
&lt;br&gt;
The second option is close.  I want to add the column to the datatable and be able to populate it like any other field on the business object, except it won't get saved. I don't need to populate the new field after filling the object. &lt;br&gt;
&lt;br&gt;
Example:  I want to add a boolean field to the internal datatable called 'cs_Processed'.&lt;br&gt;
&lt;br&gt;
I want to be able to set the field cs_Processed = True as I process the rows somewhere in a update routine. After the update is done, I want to loop through the business object and check to see what rows were not processed correctly, cs_Processed = False.&lt;br&gt;
&lt;br&gt;
Hope that helps clarify.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Tim&lt;br&gt;</description><pubDate>Wed, 28 Oct 2009 08:44:02 GMT</pubDate><dc:creator>Tim Dol</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25024.aspx</link><description>Hi Dustin,&lt;br&gt;
&lt;br&gt;
Very good explanation, thanks!&lt;br&gt;
&lt;br&gt;
BTW, glad to see you back in town :P</description><pubDate>Wed, 28 Oct 2009 08:37:23 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25022.aspx</link><description>Sounds like you want to add a column to your BO but [i]not[/i] expose it using a strong-typed property. You have two options here:&lt;/P&gt;&lt;P&gt;1) Return the column in your SQL query that fills the BO&lt;/P&gt;&lt;P&gt;2) Stuff the values into the BO in .NET after it gets filled&lt;/P&gt;&lt;P&gt;[b]First Option[/b]&lt;/P&gt;&lt;P&gt;If those fields would be present in your query, you can just include them in it and they will be accessible on the row, but not exposed through a strong-typed property.&lt;/P&gt;&lt;P&gt;So, if you have a "Customer" BO with "cs_FirstName", "cs_LastName", and "cs_ID", but want to add a calculated status column of "cs_Status", then you could formulate your SQL query like this:&lt;/P&gt;&lt;P&gt;[code]SELECT&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs_FirstName,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs_LastName,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs_ID,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (your calculation query here) AS cs_Status&lt;BR&gt;FROM Customers[/code]&lt;/P&gt;&lt;P&gt;Once you use that to fill your BO, you can access that status column by referring to the current row:&lt;/P&gt;&lt;P&gt;[code]CType(MyCustomerBO.CurrentRow.Item("cs_Status"), String)[/code]&lt;/P&gt;&lt;P&gt;Note that since it isn't strong typed, you will probably want to specify the type when you reference that column by using a CType.&lt;/P&gt;&lt;P&gt;[b]Second Option[/b]&lt;/P&gt;&lt;P&gt;For the second option, the cleanest thing would probably be to create a method to add the values for you. The method is basically going to take the internal datatable of the business object, add a column, and then populate that column for each item in the BO. Again you'll want to do this [i]after[/i] the BO gets populated:&lt;/P&gt;&lt;P&gt;[code]Private Sub CalculateStatus(ByRef dt As DataTable)&lt;BR&gt;&amp;nbsp;&amp;nbsp; '-- Establish Locals&lt;BR&gt;&amp;nbsp;&amp;nbsp; Dim MyStatus As String = ""&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; '-- Add column&lt;BR&gt;&amp;nbsp;&amp;nbsp; dt.Columns.Add(New DataColumn("cs_Status))&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; '-- Iterate through the rows and set the status&lt;BR&gt;&amp;nbsp;&amp;nbsp; For Each row As DataRow In dt.Rows&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyStatus = [i]*Your Status Calculation Here*[/i]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Item("cs_Status") = MyStatus&lt;BR&gt;&amp;nbsp;&amp;nbsp; Next&lt;BR&gt;End Sub[/code]&lt;/P&gt;&lt;P&gt;You would then call that method by passing over the datatable:&lt;/P&gt;&lt;P&gt;[code]CalculateStatus(MyCustomersBO.CurrentDataTable)[/code]&lt;/P&gt;&lt;P&gt;And would reference the resulting status item in the same way as if you had passed the value back from SQL:&lt;/P&gt;&lt;P&gt;[code]CType(MyCustomerBO.CurrentRow.Item("cs_Status"), String)[/code]</description><pubDate>Wed, 28 Oct 2009 08:31:40 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: Adding Custom Fields To BO Datatable</title><link>http://forum.strataframe.net/FindPost25021.aspx</link><description>I should add that I DO NOT want these fields to show up when I bind the business object to a grid. They should stay hidden.</description><pubDate>Wed, 28 Oct 2009 07:18:59 GMT</pubDate><dc:creator>Tim Dol</dc:creator></item></channel></rss>