尝试更新SQL数据时ASP.NET Webforms错误

时间:2017-11-14 13:11:43

标签: asp.net sql-server vb.net stored-procedures webforms

我的问题是如何使用存储过程更新ASP.NET列表视图中的数据。

每当我尝试更新listview中的任何数据时,我都会收到一条错误消息,指出我的存储过程有too many arguments specified

我查看了所有代码,并且我的所有参数似乎都与我的存储过程相匹配,因此我认为这可能与我创建listview的方式有关(只需使用visual将其拖放到设计视图中)工作室2015)或我的存储过程有问题。

我已经在这个问题上坚持了大约一天了,我觉得我在这里错过了一些非常简单的东西,但却无法完全理解它。

如果有人能帮助我,我会非常感激。我正在使用的这个应用程序使用vb.net作为后端并使用ASP.NET Web表单。下面是我正在处理的页面的代码。

ASP.NET页面(由于它使用母版页和其他一些外部资源,可能无法正常工作)

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/MasterPage.Master" CodeBehind="CodeManagement.aspx.vb" Inherits="OcasNS.CodeManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderInHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPH1_DontUseInAContentPageItsJustForTheseJavaScriptFiles" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <p>Course Code:<asp:TextBox ID="TextBox1" runat="server" Height="18px"></asp:TextBox>
</p>
    &nbsp;<br />
    <p>Course Title:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </p>
&nbsp;<br />
    <p>Class/Group:<asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </p>
    <p>Career Tech Course Type:
        <asp:DropDownList ID="DropDownList2" runat="server">
        </asp:DropDownList>
    </p>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OKECSTestConnectionString %>" SelectCommand="spCodeManagementLookup" SelectCommandType="StoredProcedure" UpdateCommand="spCodeManagementUpdate" UpdateCommandType="StoredProcedure">
        <UpdateParameters>
            <asp:Parameter Name="ClassGroupID" Type="Int32" />
            <asp:Parameter Name="CourseDescription" Type="String" />
            <asp:Parameter Name="ClassSubjectCode" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
&nbsp;<asp:ListView ID="ListView1" runat="server" DataKeyNames="ClassGroupID" DataSourceID="SqlDataSource1">
        <AlternatingItemTemplate>
            <tr style="background-color:#FFF8DC;">
                <td>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
                </td>
                <td>
                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                </td>
                <td>
                    <asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="background-color:#008A8C;color: #FFFFFF;">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                </td>
                <td>
                    <asp:Label ID="ClassGroupIDLabel1" runat="server" Text='<%# Eval("ClassGroupID") %>' />
                </td>
                <td>
                    <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ClassSubjectCodeTextBox" runat="server" Text='<%# Bind("ClassSubjectCode") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr>
                    <td>No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                </td>
                <td>&nbsp;</td>
                <td>
                    <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ClassSubjectCodeTextBox" runat="server" Text='<%# Bind("ClassSubjectCode") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr style="background-color:#DCDCDC;color: #000000;">
                <td>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
                </td>
                <td>
                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                </td>
                <td>
                    <asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr runat="server" style="background-color:#DCDCDC;color: #000000;">
                                <th runat="server"></th>
                                <th runat="server">ClassGroupID</th>
                                <th runat="server">Description</th>
                                <th runat="server">ClassSubjectCode</th>
                            </tr>
                            <tr id="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <SelectedItemTemplate>
            <tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
                <td>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
                </td>
                <td>
                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                </td>
                <td>
                    <asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>
    <br />
    &nbsp;<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:CommandField ShowEditButton="True" />
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
    <br />
    <br /> 

    <button type="button">Save</button>
    <button type="button">Cancel</button>
    <button type="button">Export To Excel</button>

</asp:Content>

更新存储过程(导致错误的过程)

@ClassGroupID INT,
@CourseDescription VARCHAR(100),
@ClassSubjectCode VARCHAR(20)

UPDATE [dbo].[tb_oecs_CodeClassGroup]
    SET [Description] = @CourseDescription
    , [ClassSubjectCode] = @ClassSubjectCode
WHERE ClassGroupID = @ClassGroupID    

查找存储过程(这会将数据加载到Listview中)

SELECT DISTINCT
    g.ClassGroupID
   ,g.Description
   ,g.ClassSubjectCode
FROM tb_oecs_CodeClassGroup g
JOIN tb_oecs_CodeClass c
    ON g.ClassGroupID = c.ClassGroupID
ORDER BY g.ClassGroupID

0 个答案:

没有答案