Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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'. "

 

           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.

 

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.

 

               .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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...