﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » Looping through BO fields</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 03:09:12 GMT</lastBuildDate><ttl>20</ttl><item><title>Looping through BO fields</title><link>http://forum.strataframe.net/FindPost7244.aspx</link><description>I want to create a generic&amp;nbsp;sub that will loop through the BO field collection, picking up only the database fields of course, determine the field type and if it is of type String, trimend.&lt;/P&gt;&lt;P&gt;Right now I have code like this in the CheckRulesOnCurrentRow event:&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Trim off trailing spaces&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.ClassType = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.ClassType.TrimEnd()&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.LocalState = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.LocalState.TrimEnd()&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.OffenseClass = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.OffenseClass.TrimEnd()&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.DescriptionText = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.DescriptionText.TrimEnd()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;and so forth for every string based field.&amp;nbsp; I would like to do something like (pseudo code):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Public Sub TrimAll(ByRef MyBO As BusinessObject)&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each DBField In MyBO ' How to determine the property is a DBField???&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If DBField.Type = StringType&amp;nbsp; ' Is it stored in the BO as a String or as the DBType?&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; DBField.FieldValue = Me.DBField.TrimEnd()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; End If&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End For&lt;BR&gt;End Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Again this way I can create a generic sub, pass the BO to the function from the CheckRulesOncurrentRow event and have the fields trimmed for me instead of listing dozens sometimes hundreds (depends on table) of fields to do the same.&lt;/P&gt;&lt;P&gt;Sorry for all of the newbie type questions!&lt;/P&gt;&lt;P&gt;Ideas?&lt;/P&gt;&lt;P&gt;Ben&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Fri, 02 Mar 2007 08:51:45 GMT</pubDate><dc:creator>Ben Kim</dc:creator></item><item><title>RE: Looping through BO fields</title><link>http://forum.strataframe.net/FindPost7260.aspx</link><description>Oh, and you won't have to pass the business object by reference... ByVal will work fine since you aren't going to return a different business object to the calling method... business objects are classes, which are already reference types.</description><pubDate>Fri, 02 Mar 2007 08:51:45 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Looping through BO fields</title><link>http://forum.strataframe.net/FindPost7259.aspx</link><description>You could cycle through the fields in the AllFields collection like this:&lt;/P&gt;&lt;P&gt;For Each field As String In BO.AllFields&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select Case BO.FieldDbTypes(field)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case System.Data.DbType.String, System.Data.DbType.StringFixedLength, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Data.DbType.AnsiString, System.Data.DbType.AnsiStringFixedLength&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Trim the field&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BO.Item(field) = CType(BO.Item(field), String).Trim()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Do whatever else you want to do to the other data types&lt;BR&gt;Next</description><pubDate>Fri, 02 Mar 2007 08:50:43 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>