Casting Error

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
I'm trying to call a stored procedure, but i dont think it actually gets that far (thats why its not in the database section). With the following code i get returned the following error :

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

Visual Basic:
            Dim cmUpdateUser As New SqlCommand("dbo.up_MaintainUsers", conn)

            cmUpdateUser.CommandType = CommandType.StoredProcedure
            conn.Open()

            With cmUpdateUser.Parameters
                .Add("UserID", SqlDbType.UniqueIdentifier).Value = strUserID
                .Add("Username", SqlDbType.NVarChar, 15).Value = strUserName
                .Add("FirstName", SqlDbType.NVarChar, 15).Value = strFirstName
                .Add("Surname", SqlDbType.NVarChar, 15).Value = strSurname
                .Add("Email", SqlDbType.NVarChar, 15).Value = strSurname + "@intier.com"
                .Add("RoleName", SqlDbType.NVarChar, 15).Value = strRole
                .Add("Department", SqlDbType.NVarChar, 15).Value = strDepartment
                .Add("AuthorisationLimit", SqlDbType.SmallInt).Value = intAuthLimit
            End With

            'Execute the command checking the returned result
            Dim ReturnResult As Integer = cmUpdateUser.ExecuteNonQuery()

Whilst debugging this is the line that raises the problem.

Visual Basic:
Dim ReturnResult As Integer = cmUpdateUser.ExecuteNonQuery()

However i'm guessing it has something to do with this line, as its the only one that fits the error message.

Visual Basic:
                .Add("UserID", SqlDbType.UniqueIdentifier).Value = strUserID

Could someone please tell me whether you can put a string into a uniqueidentifier like this? If not how would i do it? Or does the error look like it originated from elsewhere?

Thanks
 
Back
Top