|
-
May 2nd, 2004, 06:41 AM
#1
Thread Starter
Fanatic Member
Handling nulls from database query
Hi
In VB6 you would handle null columns as follows:
VB Code:
Dim lcStrValue as string
Dim lcObjRcs as ADODB.Recordset
lcStrValue = "" & lcObjRcs!Surname
I am now using VB.NET and picking up values from a DataRow object and getting an exception about DBNull.
How do I handle Null in the code below assuming the Surname column in the table is null.
VB Code:
Dim oDataRow As DataRow
For Each oDataRow in dtTable.Rows
strSurname = oDataRow.Item("Surname")
Next
Thanks
Last edited by Mr.No; May 3rd, 2004 at 05:31 AM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
May 2nd, 2004, 01:03 PM
#2
Thread Starter
Fanatic Member
[RESOLVED]
I found this article on MSDN
Much ADO About Nothing
I find the handling of nulls still cumbersome though. Ideally I would prefer amethod or property on the ADO.NET object like object.ValueIfNull. The caller could set a value in this property before making the query and then whenever a column would be null the datarow would return the value set in ValueIfNull.......
Last edited by Mr.No; May 2nd, 2004 at 01:09 PM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
May 3rd, 2004, 07:57 AM
#3
New Member
You may try to use ISDBNull() method to determine if the field is null
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
|