|
-
Mar 24th, 2004, 05:31 PM
#1
Thread Starter
Frenzied Member
Casting
How do you cast a 'null' value into a 'string'? i cant find ANY info on that. If it's not possible, what a way around this when a databse field has a null value in it?
-
Mar 24th, 2004, 06:44 PM
#2
Addicted Member
VB Code:
Dim myString As String
If IsDBNull(myRow.Item("Example")) = True Then
myString = ""
Else
myString = CStr(myRow.Item("Example")).TrimEnd
End If
-
Mar 24th, 2004, 07:04 PM
#3
PowerPoster
OR:
Code:
Dim myString As String
If myRow.Item("Example") Is DBNull.Value Then
myString = ""
Else
myString = CStr(myRow.Item("Example")).TrimEnd
End If
-
Mar 25th, 2004, 11:56 AM
#4
Thread Starter
Frenzied Member
neither one worked. It's coming from a database table and I get this message:
cast from type 'DBNull' to type 'String' is not valid
I thought for sure that code y'all had would work.
-
Mar 25th, 2004, 05:21 PM
#5
I used this for a quick project
VB Code:
Private Function DBReturn(ByVal objValue As Object) As Object
If TypeOf (objValue) Is DBNull Then
Return Nothing
Else
Return objValue
End If
End Function
and then
VB Code:
'cast The object type returned by DBReturn to the proper Data type
'so...
Msgbox (CStr(DBReturn(myRow.Item("Example"))).TrimEnd)
I am sure that someone will post a more elegant solution but this works..
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Mar 25th, 2004, 06:40 PM
#6
I wonder how many charact
Being that a textbox should have nothing for text when the form loads, a simple:
VB Code:
If Not(myrow.Item(0)) Is DbNull.Value Then myTextbox.Text = myrow.item(0)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|