sql update方法没有更新或删除

时间:2012-09-12 19:22:08

标签: c# asp.net sql

我正在开发一个网站,并且有一个带有选择按钮的GridView,单击时会显示一个DetailsView。当我尝试使用update命令更改详细信息视图中的数据或使用update命令删除记录时,没有任何反应。我不明白为什么这不是更新或删除记录。这是代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="OverwriteChanges"
    ConnectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"  
    DeleteCommand="DELETE FROM [aspnet_Membership] WHERE [UserName] =@original_UserName AND [FirstName]= @original_FirstName AND [LastName]= @original_LastName"
    OldValuesParameterFormatString="original_{0}"
    SelectCommand="SELECT * FROM [aspnet_Membership]" 

    UpdateCommand="UPDATE [aspnet_Membership] SET [FirstName] = @FirstName, [LastName] = @LastName, [Company] = @Company, [PartsList] = @PartsList, 
                  [UserName] = @UserName, [PasswordQuestion] = @PasswordQuestion, [PasswordAnswer] = @PasswordAnswer, [Role] = @Role, [Comment] =@Comment
                  WHERE [FirstName] = @original_FirstName AND [LastName] = @original_LastName AND [Company] = @original_Company AND 
                  [PartsList] = @original_PartsList AND [UserName] = @original_UserName AND [PasswordQuestion] = @original_PasswordQuestion AND 
                  [PasswordAnswer] = @original_PasswordAnswer AND [Role] = @original_Role AND [Comment] =@original_Comment">
       <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="PasswordQueston" Type="String" />
            <asp:Parameter Name="PasswordAnswer" Type="String" />
            <asp:Parameter Name="Role" Type="String" />
            <asp:Parameter Name="Comment" Type="String" />
            <asp:Parameter Name="original_FirstName" Type="String" />
            <asp:Parameter Name="original_LastName" Type="String" />
            <asp:Parameter Name="original_Company" Type="String" />
            <asp:Parameter Name="original_PartsList" Type="String" />
            <asp:Parameter Name="original_UserName" Type="String" />
            <asp:Parameter Name="original_Password" Type="String" />
            <asp:Parameter Name="original_Email" Type="String" />
            <asp:Parameter Name="original_PasswordQuestion" Type="String" />
            <asp:Parameter Name="original_PasswordAnswer" Type="String" />
            <asp:Parameter Name="original_Role" Type="String" />
            <asp:Parameter Name="original_Comment" Type="String" />
       </UpdateParameters>   
       <DeleteParameters>
            <asp:Parameter Name="original_FirstName" Type="String" />
            <asp:Parameter Name="original_LastName" Type="String" />
            <asp:Parameter Name="original_Company" Type="String" />
            <asp:Parameter Name="original_PartsList" Type="String" />
            <asp:Parameter Name="original_UserName" Type="String" />
            <asp:Parameter Name="original_Password" Type="String" />
            <asp:Parameter Name="original_Email" Type="String" />
            <asp:Parameter Name="original_PasswordQuestion" Type="String" />
            <asp:Parameter Name="original_PasswordAnswer" Type="String" />
            <asp:Parameter Name="original_Role" Type="String" />
            <asp:Parameter Name="original_Comment" Type="String" />
    </DeleteParameters>      
</asp:SqlDataSource> 

编辑 GridView1代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" AllowPaging="True" 
        AllowSorting="True" DataKeyNames="UserId" Caption="Select User" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" 
        ToolTip="Select a user to view details about the selected user">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" 
                SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="First Name" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="UserName" HeaderText="User Name" 
                SortExpression="UserName" />
            <asp:BoundField DataField="Company" HeaderText="Company" 
                SortExpression="Company" />
            <asp:BoundField DataField="PartsList" HeaderText="Parts List" 
                SortExpression="PartsList" />
            <asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
        </Columns>
        <SelectedRowStyle BackColor = "Yellow" />
    </asp:GridView>       

0 个答案:

没有答案