ERROR :

System.Data.SqlClient.SqlException: Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.


I made a admin side for editing roles and user passwords if necessary.. But since the default ASPNETDB,mdf have UserID and Password in 'Unique Identifier' data type.. while I try to update the User fields from admin side (used a grid to bring complete table :p)
It gives me above error...

Help is required soon pls.. where am I missing anything ?

Recommended Answers

All 2 Replies

you can use the sqlcommand.parameters.addwithvalue("@yourParameterName", yourValue) which should be efficiënt enough to update the values... for example:

string sql = "UPDATE aspnet_Membership SET Password = @NewPassword WHERE UserId=@UserId AND ApplicationId=@ApplicationId"
oCom.CommandText=sql;
oCom.Parameters.AddWithValue("@UserId", yourUserIdValue);
oCom.Parameters.AddWithValue("@ApplicationId", "yourApplicationId");
object retVal = null;
retVal = oCom.ExecuteScalar();
if(retVal != null & retVal > -1)
  // do something with the returnvalue

Be aware that the membership api has some features for this also :)
Besides this, you should use the salt/hash (if specified in the web.config) to scamble the password. In thát case you should also update the passwordsalt concerning the passwordformat in the DB. Check both stored procedures "[aspnet_Membership_SetPassword]" and [aspnet_Membership_ResetPassword] which fields they use....

Regards,
Richard
The Netherlands

commented: Thanks for clearing things a bit, will try with it and tell you if i face any problem.. once again Thanks to you.. Have A Nice Day. +1

I don't understand you well.
I suppose you are going to use the default SQL DB to manage the user mode.
If so, it is not necessary to write your own code.
YOu can use the .NET Membership provider.
Looking forward to your success . . .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.