Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query


Scenario – I was implementing the basic CRUD operations (Create, Read, Update and Delete) by using SQLDataSource into a gridview. I defined the DataKeyNames =’Id’ inside the gridview for the primary key reference(Primary key - Id is having the datatype as UniqueIdentifier into the database). Create, Read and Delete operations has been implemented successfully, but when I tried for the update operation it was showing the below error  – 



I checked my code thoroughly and understood the problem, please have a look below-

Problem found After matching the datatype for the parameters between frontend and backend, problem has been understood. Please go through the below points -


Point 1 - Please have a look at the below stored procedure which is used in this scenario for update the records
Point 2 - Please have a look at the aspx code from where I am passing the parameters to the StoredProcedure

So the main problem is -
When we pass Id from the forntend (which type is object)to the backend (StoredProcedure ,Where Id is type of UniqueIdentifier) then both are not matching.Solution – I removed the type from the parameter of Id. 



Please try,This solved my problem. 










Post a Comment

0 Comments