468,291 Members | 1,482 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

Converting a Guid to a string

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.

Nov 19 '05 #1
3 12216
On Tue, 10 May 2005 11:53:06 -0500, Eagle <ea*************@yahoo.com>
wrote:
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()

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
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.

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op***************@wtsp01tec520.nac.hscorp.com ...
On Tue, 10 May 2005 11:53:06 -0500, Eagle <ea*************@yahoo.com>
wrote:
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()

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #3
Thanks everyone! It now works!
"Eagle" <ea*************@yahoo.com> wrote in message
news:uz**************@TK2MSFTNGP14.phx.gbl...
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.

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sandra | last post: by
1 post views Thread by vector | last post: by
1 post views Thread by Scott M. Lyon | last post: by
1 post views Thread by SealedClassSingleton | last post: by
5 posts views Thread by Michael Primeaux | last post: by
2 posts views Thread by Jeff | last post: by
4 posts views Thread by Marc | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.