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

Nullable GUIDs

n my database, in one of the table I have a GUID column with allow nulls. I have a method with a Guid? parameter that inserts a new data row in the table. However when I say myNewRow.myGuidColumn = myGuid I get the following error: "Cannot implicitly convert type 'System.Guid?' to 'System.Guid'."
0
iulianchira
Asked:
iulianchira
  • 2
  • 2
  • 2
1 Solution
 
divyeshhdoshiCommented:
please use guidcolumn= system.Guid.NewGuid()
0
 
iulianchiraAuthor Commented:
I do not want to a new GUID, i allready have the GUID I want to insert.
0
 
divyeshhdoshiCommented:
but in whatever guid it should have some value.
otherwise it will insert null in guid column.

like You have created a guid
System.Guid g=System.Guid.NewGuid()

you can not use this one
System.Guid g=new System.Guid() will create guid with blank.

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
iulianchiraAuthor Commented:
I want to have null sometimes in the column.
0
 
openshacCommented:
Guid? and Guid are different types.
you need to cast the nullable guid before assigning it to a guid value:
myNonNullableGuid = (Guid)myNullableGuid;

Open in new window

0
 
openshacCommented:
or in your case
myNewRow.myGuidColumn = (Guid)myGuid ;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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