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

前端 未结 1 1741
误落风尘
误落风尘 2021-01-13 02:27

I am creating a website now using Microsoft Visual Web Developer 2010 Express and I used the toolbox of \"createUserWizard\". Then I put the userId

相关标签:
1条回答
  • 2021-01-13 03:18

    If you want to insert GUID from your code, you should make parameter type GUID

    <asp:Parameter Name="ParamName" DbType="Guid" />
    

    And you should pass GUID value as (c#):

    SqlDataSource1.InsertParameters["ParamName"].DefaultValue = System.Guid.NewGuid().ToString();
    

    If you want to pass a string value, you have to use CONVERT(UNIQUEIDENTIFIER,'YOUR VALUE') in the insert query like this:

    InsertCommand="INSERT INTO [Order] ([UserId], [etc]) 
    VALUES (CONVERT(UNIQUEIDENTIFIER,@UserId), @etc)" 
    
    0 讨论(0)
提交回复
热议问题