Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid cast from 'System.String' to 'System.Guid'.

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I am trying to update a field in a table using a uniqueidentifier field as a parameter.

Here is my stored procedure

Code:
USE [xforafrica]
GO
/****** Object:  StoredProcedure [dbo].[UpdateVerified]    Script Date: 09/02/2012 22:02:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UpdateVerified]
(

@Guid uniqueidentifier



)
AS
BEGIN


SET NOCOUNT ON;

UPDATE dbo.Registrations
SET Verified = 1
WHERE Guid = @Guid


END

Here is my asp.net code

Code:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load


        Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("xforafricaConnectionString").ConnectionString
        Dim con As New SqlConnection(ConnString)
        Dim cmd As New SqlCommand()
        Dim guid As String = Request.QueryString("guid").ToString()

        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "UpdateVerified"
        cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid
        

        cmd.Connection = con
        Try
            con.Open()
            cmd.ExecuteScalar()

        Catch ex As Exception
            Throw ex
        Finally
            con.Close()
            con.Dispose()
        End Try
       
    End Sub

Basically when a user registers they are sent an email with a link which contains a querystring with the uniqueidentifier from the table. when they click on the link it takes them to the activation page and it should update the database verified field to true using the querystring.

 
Not sure, but try this:
Code:
cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = new guid(guid)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top