• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3048
  • Last Modified:

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!
0
kevman123
Asked:
kevman123
  • 3
  • 3
1 Solution
 
Bob LearnedCommented:
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
0
 
kevman123Author Commented:
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.
0
 
Bob LearnedCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kevman123Author Commented:
Yes, I think we've added some code in that section, but didn't know if we could assign it directly to the variable.
0
 
Bob LearnedCommented:
Nope, you can't set the variable.

Bob
0
 
kevman123Author Commented:
Ok - thanks for the info!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now