1

我有一个显示所有注册用户及其一些信息的 GridView,当您选择侧面的“选择”链接时,它会显示一个包含与该用户相关的所有详细信息的 DetailsView。选择工作正常并更新所选用户的详细信息视图,当我尝试编辑 DetailsView 时,它将更新数据库并在更改字段时填写为所有用户更新的信息(例如,如果我更改客户名字,每个注册的人都会得到这个名字)。这是我的 SqlDataSource 的 aspx 代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT * FROM [UserProfile] ORDER BY [Email], [LastName], [Company]"
        UpdateCommand="UPDATE [UserProfile] SET [LastName] = @LastName, [PartsList] = @PartsList, [UserName] = @UserName, [Question] = @Question, 
                      [Answer] = @Answer, [Role] = @Role 
                      WHERE [FirstName] = FirstName AND [Company] = Company">
            <UpdateParameters>
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="Company" Type="String" />
                <asp:Parameter Name="PartsList" Type="String" />
                <asp:Parameter Name="UserName" Type="String" />
                <asp:Parameter Name="Password" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="Question" Type="String" />
                <asp:Parameter Name="Answer" Type="String" />
                <asp:Parameter Name="Role" Type="String" />                    
            </UpdateParameters>
    </asp:SqlDataSource>
4

1 回答 1

0

你忘@original_了你的Where参数

将 UpdateCommand 更改为:

UPDATE [UserProfile] SET [LastName] = @LastName, [PartsList] = @PartsList, [UserName] = @UserName, [Question] = @Question, [Answer] = @Answer, [Role] = @Role WHERE [FirstName] = @original_FirstName AND [Company] = @original_Company

于 2012-09-06T19:52:20.463 回答