Converting a Guid to a string

  • Thread starter Thread starter Eagle
  • Start date Start date
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.
 
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()
 
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.
 
Back
Top