Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2689
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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