|
-
Feb 9th, 2012, 02:32 AM
#1
Thread Starter
Fanatic Member
filling values from dataset
Hi All,
I have a need to assign values from my dataset to a variable but when i use string (which its normally text) and the item in that row of the dataset is empty it tells me that conversion from DBnull to string is not valid
how do I get around this?
-
Feb 9th, 2012, 03:34 AM
#2
Re: filling values from dataset
That depends how you want to handle null values. If you want a null from the database to correspond to Nothing in VB then you will have to test for null first and only get the value if it is not null. There are various ways to do that but the DataRow class has its own method for doing so so, if you're using a DataRow, you should use that, e.g.
Code:
Dim name = If(myDataRow.IsNull("Name"), CStr(Nothing), CStr(myDataRow("Name")))
If you want a null from the database to correspond to an empty string then you can simply call ToString on the field because DBNull.ToString returns an empty string.
-
Feb 9th, 2012, 07:30 PM
#3
Thread Starter
Fanatic Member
Re: filling values from dataset
lovely, .tostring was what i was after.
Thanx heaps
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
|