Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Casting problem String -> Guid

Casting problem String -> Guid

Scheduled Pinned Locked Moved Visual Basic
helpdatabasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Taylor
    wrote on last edited by
    #1

    I have a DropDownList where the ValueField is a guid as a string. I then need to pass this as a guid into a stored procedure. If I try and cast a string to a guid I get the following error: Value of type 'String' cannot be converted to 'System.Guid'. What do I need to do to get this to work? Jim

    D 1 Reply Last reply
    0
    • J Jim Taylor

      I have a DropDownList where the ValueField is a guid as a string. I then need to pass this as a guid into a stored procedure. If I try and cast a string to a guid I get the following error: Value of type 'String' cannot be converted to 'System.Guid'. What do I need to do to get this to work? Jim

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The String object can't convert a string to a GUID because it doesn't know how. However, the GUID object does know how to parse up certain format strings into GUID's. The following code segment demonstrates this:

          Dim guidString As String = "936DA01F-9ABD-4d9d-80C7-02AF85C822A8"
          Dim objGUID As Guid
      
          objGUID = New System.Guid(guidString)
          Debug.WriteLine("String GUID: " & guidString)
          Debug.WriteLine("GUID object: " & objGUID.ToString)
      

      Documentation on the GUID object can be found here[^]. This same documentation can also be found in the Visual Studio help, in the Index, under 'Guid'. RageInTheMachine9532

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The String object can't convert a string to a GUID because it doesn't know how. However, the GUID object does know how to parse up certain format strings into GUID's. The following code segment demonstrates this:

            Dim guidString As String = "936DA01F-9ABD-4d9d-80C7-02AF85C822A8"
            Dim objGUID As Guid
        
            objGUID = New System.Guid(guidString)
            Debug.WriteLine("String GUID: " & guidString)
            Debug.WriteLine("GUID object: " & objGUID.ToString)
        

        Documentation on the GUID object can be found here[^]. This same documentation can also be found in the Visual Studio help, in the Index, under 'Guid'. RageInTheMachine9532

        J Offline
        J Offline
        Jim Taylor
        wrote on last edited by
        #3

        Great! Thanks for you help, I was going down the wrong track trying to cast a string. I managed to get this to work but I guess the datakeys are already in the correct format. Dim FileUID As Guid = CType(dgMyDataGrid.DataKeys(e.Item.ItemIndex), System.Guid) Jim

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups