locked
Error: Operand type clash: uniqueidentifier is incompatible with int???? Help RRS feed

  • Question

  • User-1467402512 posted

    Hey, I am getting this error:

    Error: Operand type clash: uniqueidentifier is incompatible with int

    My SQL datasource:

    <asp:SqlDataSource ID="CommentsDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:CommentsConnectionString %>"
    DeleteCommand="DELETE FROM [GuestbookComments] WHERE [CommentId] = @CommentId">
    <DeleteParameters>
    <asp:Parameter Name="CommentId" Type="Int32" />
    </DeleteParameters>
    </asp:SqlDataSource>

    Inside my Guestbook Comments Table I have a column for:
    Comment ID which is the Primary Key
    Type: UniqueIdentifer
    Default: (newid())

    I am not sure why I am getting this message. 



    Wednesday, March 9, 2016 6:46 PM

Answers

  • User1578460427 posted

    You are getting this error because you are trying to pass the parameter @CommentId value as an Int32 in to a SQL query that calls the CommentID field in the database, which has been setup with the UniqueIdentifier data type (i.e. a 16 byte GUID) so the two data types are not the same, so are not compatible.

    Try:

    <DeleteParameters>
    <asp:Parameter Name="CommentId" DbType="Guid" />
    </DeleteParameters>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 9, 2016 7:47 PM

All replies

  • User1578460427 posted

    You are getting this error because you are trying to pass the parameter @CommentId value as an Int32 in to a SQL query that calls the CommentID field in the database, which has been setup with the UniqueIdentifier data type (i.e. a 16 byte GUID) so the two data types are not the same, so are not compatible.

    Try:

    <DeleteParameters>
    <asp:Parameter Name="CommentId" DbType="Guid" />
    </DeleteParameters>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 9, 2016 7:47 PM
  • User-1716253493 posted

    The sqldatasource code like above usualy using int (autoincrease) as ID column

    Thursday, March 10, 2016 12:47 AM