String Comparison in BO is not working properly


Author
Message
Jeff Pagley
Jeff Pagley
StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
I have setup a field string value in the BO Mapper custom field properties as follows:

Return Alternate on Null/Set Null on Alternate (reference type)

NULL Replacement Value: ""

The problem is when I clear the field value on the form's control and save, the BO is writing an empty string back to the database instead of NULL.

However, when I modify your BO code by changing [If value IsNot "" Then] to

[If value.Length > 0 Then] (see modified code below),  the logic works and the BO writes the NULL value back to the database.

What is going on here?

''' <summary>

''' JobAddress

''' </summary>

''' <remarks></remarks>

<Browsable(False), _

BusinessFieldDisplayInEditor(), _

Description("JobAddress"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public Property [JobAddress]() As System.String

Get

Dim loValue As Object

loValue = Me.CurrentRow.Item("JobAddress")

If loValue Is DBNull.Value Then

Return ""

Else

Return CType(loValue, System.String)

End If

End Get

Set(ByVal value As System.String)

' If value IsNot "" Then

If value.Length > 0 Then

Me.CurrentRow.Item("JobAddress") = value

Else

Me.CurrentRow.Item("JobAddress") = DBNull.Value

End If

End Set

End Property


StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Being a string, you might want to change it from the reference type option to value type option (since strings are kinda treated like value types being immutable and all...).  That way, the test will be "If value <> "" Then" which should work.  Also, you might consider using String.Empty as the alternate value instead of "" since String.Empty is already interned.
Jeff Pagley
Jeff Pagley
StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)StrataFrame User (469 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
I am confused. Why did you tell this user to use the Reference type for strings here http://forum.strataframe.net/FindPost10792.aspx  and you are telling me to use the value type for strings.
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, the difference is what you're using for the alternate value.  He was using "Nothing" (I think) which requires that VB use the Is and IsNot operators, while String.Empty or "" requires that you use the = and <> operators (which get set by using the value type).  So, if you want to use Nothing as your alternate value, then use reference type, but if you want to use String.Empty or "", then use the value type because it will change the operators that are used in the test.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search