Reynan
Reynan

Reputation: 261

Inserting uniqueidentifier type in database. Conversion error

I tried remove (Type="Object") and it still generate error in Password when inserting data.

TABLE
ProfileId int
Firstname nvarchar
Lastname nvarchar
Contact nvarchar
Username nvarchar
Password uniqueidentifier

<asp:SqlDataSource ID="sds2" runat="server" ConnectionString="<%$ ConnectionStrings:SanitexConnectionString %>" 
        SelectCommand="SELECT * FROM [tblProfile]"
        InsertCommand="INSERT INTO [tblProfile] (ProfileId,FirstName,LastName,Contact,UserName,Password) VALUES(@ProfileId,@FirstName,@LastName,@Contact,@UserName,@Password)"
        >
        <InsertParameters>
            <asp:Parameter Name="ProfileId" Type="Int16" />
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="Lastname" Type="String" />
            <asp:Parameter Name="Contact" Type="String" />
            <asp:Parameter Name="UserName" Type="String" />
            <asp:Parameter Name="Password" />
        </InsertParameters>
    </asp:SqlDataSource>

Upvotes: 0

Views: 111

Answers (1)

AbdulRahman Ansari
AbdulRahman Ansari

Reputation: 3057

The only string which can be successfully inserted in uniqueidentifier column is in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, in which each x is a hexadecimal digit in the range 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid uniqueidentifier value.

  • Hence, make sure that the password you are inserting is in the above format or, change the data type of the Password column.

Reference: http://technet.microsoft.com/en-us/library/ms187942.aspx

Upvotes: 1

Related Questions