删除查询会产生两个不同的错误

时间:2014-03-09 05:21:29

标签: c# asp.net sql gridview

我的网站上有几个网格视图。这是代码:

changeSlides.aspx:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" DataSourceID="AccessDataSource1">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
            ReadOnly="True" SortExpression="ID" />
        <asp:ImageField DataImageUrlField="picPath" 
        DataImageUrlFormatString="PlaceImages/{0}" HeaderText="Picture"  ControlStyle-CssClass="editPhotoGridFormat">
        <ControlStyle CssClass="editPhotoGridFormat"></ControlStyle>
            </asp:ImageField>
        <asp:BoundField DataField="PicPath" HeaderText="Filename" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
        <asp:BoundField DataField="Country" HeaderText="Country" 
            SortExpression="Country" />
    </Columns>
</asp:GridView>

EditBlogPost.aspx:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
    AutoGenerateEditButton="True" 
    DataSourceID="AccessDataSource1"
    AutoGenerateColumns="False" DataKeyNames="ID"
    AlternatingRowStyle-BackColor="Gray"  
    AlternatingRowStyle-CssClass="editGridFormat" RowStyle-CssClass="editGridFormat"        
    RowStyle-VerticalAlign="Top" 
    onselectedindexchanged="GridView1_SelectedIndexChanged">

    <AlternatingRowStyle BackColor="Gray" CssClass="editGridFormat"></AlternatingRowStyle>

    <Columns>
        <asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" />
        <asp:BoundField DataField="ID" HeaderText="ID" />
        <asp:BoundField DataField="BlogTitle" HeaderText="BlogTitle" 
            SortExpression="BlogTitle" />
        <asp:ImageField DataImageUrlField="Image" HeaderText="Image"
            DataImageUrlFormatString="~/PlaceImages/{0}" ControlStyle-CssClass="editPhotoGridFormat"
            AlternateText="Either a wrong file type or a misspelled file name has occurred" 
            NullDisplayText="No picture on file" >
        <ControlStyle CssClass="editPhotoGridFormat"></ControlStyle>
        </asp:ImageField>
        <asp:BoundField DataField="Caption" 
            HeaderText="Caption for Picture on Homepage" />
        <asp:TemplateField headertext="Text for the homepage">
            <EditItemTemplate>
                <asp:TextBox id="PicTextBox" runat="server" text='<%# Bind("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
            </EditItemTemplate>
            <ItemTemplate>
                <%# Eval("PicText")%>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="TravelDate" HeaderText="Date of Travel" 
            SortExpression="TravelDate" DataFormatString="{0:MMMMMMMMM, dd, yyyy }" HtmlEncode="false" />
        <asp:TemplateField headertext="Top of the Blog Post">
            <EditItemTemplate>
                <asp:TextBox id="BeginTextBox" runat="server" text='<%# Bind("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
            </EditItemTemplate>
            <ItemTemplate>
                <%# Eval("BeginText")%>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="City" HeaderText="City" />
        <asp:BoundField DataField="Country" HeaderText="Country" 
            SortExpression="Country" />
        <asp:TemplateField headertext="Text at the End of the Post">
            <EditItemTemplate>
                <asp:TextBox id="EndTextBox" runat="server" text='<%# Bind("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
            </EditItemTemplate>
            <ItemTemplate>
                <%# Eval("EndText")%>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>

<RowStyle VerticalAlign="Top" CssClass="editGridFormat"></RowStyle>    
</asp:GridView>

EditPeoplePhotos.aspx:

    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
    DataSourceID="AccessDataSource1" Width="493px">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowSelectButton="True" />
        <asp:ImageField DataImageUrlField="picPath" 
            DataImageUrlFormatString="photos/PeoplePhotos/{0}" HeaderText="Picture"  ControlStyle-CssClass="editPhotoGridFormat">
        </asp:ImageField>
    </Columns>
</asp:GridView>

我的更新语句有效,但我的删除语句在三个网格视图中的两个中不起作用。我的相应删除语句几乎都是相同的:“DELETE FROM(表名)WHERE ID =?”但是我得到了不同的错误代码,如下所示:

对于changeSlides.aspx,它显示“具有相同密钥的条目已存在” 对于EditBlogPosts.aspx,它工作正常。它删除了博客。 对于EditPeoplePhotos.aspx,它说“没有给出一个或多个必需参数的值”

每个页面在我的数据库中使用一个单独的,不相关的表,每个查询只引用一个表,因此没有使用外键。

发生了什么事?

0 个答案:

没有答案