DeleteCommand无法在asp.net 2.0中运行

时间:2013-03-27 18:04:14

标签: asp.net sql sql-server vb.net

我有以下SqlDataSource:

<asp:SqlDataSource ID="LDetails" runat="server" ConnectionString="<%$ ConnectionStrings:NormCon %>"
    SelectCommand ="SELECT l.Link_ID,l.Link_Name,l.Link_Path,l.Link_Desc
                    FROM HyperLinks l
                    WHERE l.link_id = @Link_ID;"
    UpdateCommand ="UPDATE Hyperlinks SET Link_Name = @Link_Name, Link_Path = @Link_Path, Link_Desc = @Link_Desc WHERE Link_ID = @Link_ID;"
    DeleteCommand ="DELETE FROM Hyperlinks_Groups WHERE Join_Link = @Link_ID; DELETE FROM Hyperlinks WHERE Link_ID = @Link_ID;"
    <SelectParameters>
        <asp:ControlParameter Name="Link_ID" ControlID="linkList" PropertyName="SelectedDataKey.Value" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Link_Name" />
        <asp:Parameter Name="Link_Path" />
        <asp:Parameter Name="Link_Desc" />
        <asp:ControlParameter Name="Link_ID" ControlID="linkList" PropertyName="SelectedDataKey.Value" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:ControlParameter Name="Link_ID" ControlID="linkList" PropertyName="SelectedDataKey.Value" />
    </DeleteParameters>
</asp:SqlDataSource>

这是我的详细信息:

<asp:DetailsView ID="LinkDetails" runat="server" DataSourceID="LDetails" 
    DataKeyNames="Link_ID" AutoGenerateRows="False" OnItemDeleted="deleteLinkReload" >
    <Fields>
    <asp:BoundField DataField="Link_ID" />
        <asp:TemplateField HeaderText="Link Name">
            <ItemTemplate>
                <asp:Label ID="lblLinkName" runat="server" Text='<%# Bind("Link_Name") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtLinkName" runat="server" Text='<%# Bind("Link_Name") %>' MaxLength="50" /> 
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Link">
            <ItemTemplate>
                <asp:HyperLink ID="lnkLinkPath" runat="server" Text='<%# Bind("Link_Path") %>' NavigateUrl='<%# Bind("Link_Path") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtLinkActual" runat="server" Text='<%# Bind("Link_Path") %>' MaxLength="250" /> 
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Comment">
            <ItemTemplate>
                <asp:Label ID="lblLinkComment" runat="server" Text='<%# Bind("Link_Desc") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtLinkComment" runat="server" Text='<%# Bind("Link_Desc") %>' MaxLength="250" />
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="linkDetailsEdit" runat="server" CommandName="edit" Text="Edit" />
                <asp:LinkButton ID="linkDetailsDelete" runat="server" OnClientClick="return confirm('OK to delete link?');" CommandName="Delete" Text="Delete Link" /> <%--OnClick="DeleteLink" --%>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:LinkButton ID="linkDetailsAccept" runat="server" CommandName="update" Text="Accept" />
                <asp:LinkButton ID="linkDetailsCancel" runat="server" CommandName="Cancel" CausesValidation="false" Text="Cancel" />
            </EditItemTemplate>
        </asp:TemplateField>
    </Fields>
</asp:DetailsView>

当我单击详细信息视图中与此链接的删除按钮时,页面将刷新,但不会删除该项目。我认为DeleteCommand返回0行或错误,没有我能够捕获错误。我试过看看是否有一个DeleteCommand的情况,甚至通过将SQL切换到这个:

 DeleteCommand ="INSERT INTO mis_test (string) VALUES ('Hi');"

它仍然没有做任何事情。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

尝试使用SQL Server Profiler查看数据库上运行的内容以及它给出的错误。

答案 1 :(得分:0)

我敢打赌你的连接字符串包含User Instance=trueAttachDbFileName=...之类的东西,并且在你运行delete命令后,你通过SSMS或Visual Studio(不是你的应用程序)连接并检查表

如果是这种情况,那么您需要停止使用此User Instance功能(已弃用)。这样做是为连接的任何应用程序的每个实例创建数据库的副本。

您需要做的是将数据库正确附加到SQL Server的实际实例,并从所有应用程序连接到该数据库的副本。