我有一个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>
答案 0 :(得分: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