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:
Here's my 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
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