Converting a Guid to a string

E

Eagle

How do I convert a Guid to a string? I am trying to retrieve a value from a
dataview into a string variable:

CurrentValue = drv(strColumn)

and it works fine until the strColumn is a guid column, then I tried this:

Current Value = CType(drv(strColumn), String)

and I get an error that the cast is not valid.

Thanks very much for your help.
 
C

Craig Deelsnyder

How do I convert a Guid to a string? I am trying to retrieve a value
from a
dataview into a string variable:

CurrentValue = drv(strColumn)

and it works fine until the strColumn is a guid column, then I tried
this:

Current Value = CType(drv(strColumn), String)

and I get an error that the cast is not valid.

Thanks very much for your help.

There's not a direct cast possible there (even tho you know a GUID has a
string representation)...cast it to a Guid first, then do a ToString() on
it:

CType(drv(strColumn), Guid).ToString()
 
M

Marina

No need to cast it to a guid first. Just call ToString() on it.

Also, turning Option Strict On would catch these types of problems during
compile time, as opposed to run time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top