Hi,
I have a page with several textboxes...it's a "change your account" page. One of the parameters is presented as a label instead since it is not changed ON THIS PAGE. It needs to be NULL when the account is created and entered later. But when the page loads, I get the above error. The account row is loaded from a business object LoadFromId().
How can I load the page even though this label data is NULL to start with? relevent code below.
<asp:Label ID="lblDDAccount" Runat="server"></asp:Label>
------
If currentUser.DDAccount = "" Then
lblDDAccount.Text = "enter here"
Else
lblDDAccount.Text = currentUser.DDAccount
End If
------------------
Private Sub LoadFromId()
//this is in the business object
Dim dataUser As New Data.User(myModuleSettings.ConnectionString)
Dim userRow As DataRow = dataUser.Retrieve(myUserId)
...(other items) ...
myDDAccount = CStr(userRow("DDAccount"))
End Sub
--------------------
"Look at it go, Homer; this one's gonna go for miles!"
![]() |
0 |
![]() |
I would use IsDBNull to determine if it's null, then assign an empty string value ("") to it. something like:
If IsDBNull(currentUser.DDAccount) = System.DBNull.Value Then
If currentUser.DDAccount = "" Then
lblDDAccount.Text = "enter here"
Else
lblDDAccount.Text = currentUser.DDAccount
End IfEnd If
You could also use Select Case instead. the key concept is that a DBNull is not equal to an empty string.
LIozzi
www.iozzi.net
![]() |
0 |
![]() |
Ooops..
If IsDBNull(currentUser.DDAccount) = System.DBNull.Value Then
currentUser.DDAccount = ""
lblDDAccount.Text = "enter here"
ElseIf currentUser.DDAccount = "" Then
lblDDAccount.Text = "enter here"
Else
lblDDAccount.Text = currentUser.DDAccount
End IfEnd If
LIozzi
www.iozzi.net
![]() |
0 |
![]() |
Try something like this:
If userRow("DDAccount") = DBNull.Value
myDDAccount = ""
Else
myDDAccount = CStr(userRow("DDAccount"))
End If
Darrell Norton, MVP
Darrell Norton's Blog
Please mark this post as answered if it helped you!
![]() |
0 |
![]() |
Thanks, but none of the above has solved it...might help to show that I start the loading of the objects by this statement in the pageLoad() event:
Dim currentUser As New AccBusiness.User( _
CType(Context.User, SitePrincipal))...and this is where the error msg points to in the pageLoad() sub. If this helps anyone see where I'm going wrong, plz try again to give me a suggestion. It just looks like the pageLoad() sub wants each variable stored in the LoadFromId() to have something...but I want to start with a Null in this particular field, not a default value.
Thx,
Reid C.
"Look at it go, Homer; this one's gonna go for miles!"
![]() |
0 |
![]() |
Darrell if you're still out there (or anyone else who might see my problem) you may be able to detect something from the above...I'm not getting past the exposing of the session principal "currentUser" at the start of the pageLoad sub. It is what is pulling the parameters from the LoadFromId sub in my business class...that is stopping me before I ever get to the "currentUser.DDAccount parameter even if I apply a Null test to that.
Is there something I can do in the database to handle this, or in the LoadFromId sub?
Thx much / Reid C.
"Look at it go, Homer; this one's gonna go for miles!"
![]() |
0 |
![]() |
Solved this in my query in the sproc. thanks to all who looked.....
"Look at it go, Homer; this one's gonna go for miles!"
![]() |
0 |
![]() |