Link to home
Start Free TrialLog in
Avatar of kevman123
kevman123

asked on

Setting GUID value to NULL

How do I set a GUID to NULL? When I try, I get an error saying Can't convert type System.DBNull to System.GUID.
Also, we can't use Nullable(of GUID) types.
Thanks!
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

What is the context for this question?  It might be possible to use Guid.Empty, but it is difficult to tell with that description.

Bob
Avatar of kevman123
kevman123

ASKER

For example:
Dim testGUID as GUID

testGUID = DBNull.Value
<error>

We need to save null values to the database because of foreign key requirements. If I use Guid.Empty it puts all zeros. I think the only way to handle it is to capture it on the save back to the database.
Since you aren't using a nullable GUID type, then you are going to have to process that somewhere else, since you can't set a GUID to DBNull.

Are you using a stored procedure to write to the database?

Bob
Yes, I think we've added some code in that section, but didn't know if we could assign it directly to the variable.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok - thanks for the info!