Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion failed when converting from a character string to uniqueide

Status
Not open for further replies.

joshbula

Technical User
Nov 19, 2004
45
US
I'm trying to UPDATE a row using asp GridView edit. Both attributes are uniqueidentifiers. The columns are guid in the database.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier


Here's the SqlDataSource:
Code:
    <asp:SqlDataSource ID="sqlUsers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:FBA-MPA2ConnectionString %>" 
        SelectCommand="SELECT aspnet_Users.UserName, tblUserInfo.FirstName, tblUserInfo.LastName, tblUserInfo.District, aspnet_UsersInRoles.RoleId, aspnet_Roles.RoleName AS aspnetRoleName FROM aspnet_Users INNER JOIN aspnet_UsersInRoles ON aspnet_Users.UserId = aspnet_UsersInRoles.UserId INNER JOIN tblUserInfo ON aspnet_Users.UserId = tblUserInfo.UserID INNER JOIN aspnet_Roles ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId WHERE (tblUserInfo.District = @District)" 
        UpdateCommand="UPDATE aspnet_UsersInRoles SET RoleId = '@RoleID' WHERE UserID= '@UserID'" 
        DeleteCommand="DELETE FROM aspnet_USers WHERE UserID = ''">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddDistricts" Name="District" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="UserID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="UserID" />
            <asp:Parameter Name="RoleID" />
        </UpdateParameters>
    </asp:SqlDataSource>

Here's my GridView
Code:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataSourceID="sqlUsers" DataKeyNames="UserName" >
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:TemplateField HeaderText="Delete" ShowHeader="false" InsertVisible="False">
              <ItemTemplate>
              <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="false" CommandName="Delete" OnClientClick='return confirm("Are you sure you want to delete this person?");' Text="Delete" /></ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="UserName" HeaderText="UserName" 
                SortExpression="UserName" ReadOnly="True" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" ReadOnly="True" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" 
                SortExpression="LastName" ReadOnly="True" />
            <asp:BoundField DataField="District" HeaderText="District" 
                SortExpression="District" ReadOnly="True" />
            <asp:TemplateField HeaderText="Role" SortExpression="aspnetRoleName">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlRoles" 
                        DataTextField="RoleName" DataValueField="RoleId" 
                        SelectedValue='<%# Bind("RoleId") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("aspnetRoleName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

If there is something I need in code-behind, please give it to me in Visual Basic.

Or, if there's an easier way to do this using the Membership class or RoleProvider or somehting, please point me in the right direction. I'm trying to CHANGE a role for a user, not add and delete... all my users can only be one role.

Thanks,
...Josh
 
i think i might have missed some lessons, but from what i see that doesn't look like asp, i'm not even familiar with that formatting of code, but as for the error your're getting updating unique ids is 2 fold, one thy have to be unique before and after updating, secondly, they have to maintain datatype particularly numeric... and usually it's an autoincrementing field which isn't modifyable. even cross reference table for one to many relationships they hold unique id's from other tables in them but has it's own unique id to maintain it's own records.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Josh,

You need to post your question in the ASP.NET forum. Its a very active forum and I am sure you will get an answer soon...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top