Solved

Nullable GUIDs

Posted on 2008-10-17
6
2,656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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