Solved

Nullable GUIDs

Posted on 2008-10-17
6
2,612 Views
Last Modified: 2013-11-07
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
Comment
Question by:iulianchira
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22738708
please use guidcolumn= system.Guid.NewGuid()
0
 

Author Comment

by:iulianchira
ID: 22738754
I do not want to a new GUID, i allready have the GUID I want to insert.
0
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22738775
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:iulianchira
ID: 22738785
I want to have null sometimes in the column.
0
 
LVL 6

Accepted Solution

by:
openshac earned 500 total points
ID: 22738791
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
 
LVL 6

Expert Comment

by:openshac
ID: 22738803
or in your case
myNewRow.myGuidColumn = (Guid)myGuid ;

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now