Jay1b Posted March 31, 2006 Posted March 31, 2006 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 Quote
Administrators PlausiblyDamp Posted March 31, 2006 Administrators Posted March 31, 2006 Try .Add("UserID", SqlDbType.UniqueIdentifier).Value = new Guid(strUserID ) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.