0

我正在尝试在我的网络服务中调用一个函数。相同的技术用于页面上的不同区域,但这个似乎不起作用。

这是 aspx 语法:

<asp:Repeater ID="rptDeleteTickets" runat="server">
    <ItemTemplate>
        <asp:UpdatePanel ID="DeleteTicketUpdatePanel" runat="server">
            <ContentTemplate>
                <li>
                    <asp:Label ID="lblTicketDescD" runat="server" Text='<%# Eval("typ_omschr") %>' /></li>
                <li style="border-bottom: 1px solid white;">
                    <asp:Label ID="lblTicketPriceD" runat="server" Text='<%# Eval("typ_prijs") %>' />
                    <asp:ImageButton ID="btnDeleteTicket" runat="server" ImageUrl="~/Images/minus.png" Width="20px"
                        OnCommand="btnDeleteTicket_Command" CommandName='<%# Eval("typ_id") %>' meta:resourcekey="btnDeleteTicketResource1" />
                </li>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ItemTemplate>
</asp:Repeater>

btnDeleteTicket_Command功能:

protected void btnDeleteTicket_Command(object sender, CommandEventArgs e)
{
    try
    {
        String strTypId = e.CommandName.ToString();
        int intResult = webService.Festivals_DeleteTicketFestival("1", "3");

        divResult.Visible = true;
        lblResult.ForeColor = System.Drawing.Color.White;
        if (intResult == 1)
        {
            lblResult.Text = GetLocalResourceObject("SaveSuccess").ToString();
            dsTicketsPerFestival = webService.Festivals_GetTicketTypesOfFestival(strFormIdFest);
            Session["TicketsPerFestival"] = dsTicketsPerFestival;
        }
        else if (intResult == -1)
        {
            lblResult.ForeColor = System.Drawing.Color.LightSalmon;
            lblResult.Text = GetLocalResourceObject("ErrorNoDeleted").ToString();
        }
        else if (intResult > 1)
        {
            lblResult.Text = GetLocalResourceObject("ErrorMultipleDeleted").ToString();
            dsTicketsPerFestival = webService.Festivals_GetTicketTypesOfFestival(strFormIdFest);
            Session["TicketsPerFestival"] = dsTicketsPerFestival;
        }
    }
    catch (Exception fatal)
    {
        divResult.Visible = true;
        lblResult.ForeColor = System.Drawing.Color.LightSalmon;
        lblResult.Text = GetLocalResourceObject("Error").ToString();
    }
}

网络服务的联系方式如下:

webService.Festivals_DeleteTicketFestival("1", "3");

Festivals_DeleteTicketFestival(String festId, String typId)功能:调试时,我可以看到webservice中的festId和typId为null 。

[WebMethod]
public int Festivals_DeleteTicketFestival(String festId, String typId)
{
    return Festivals_DeleteTicketFestival(festId, typId); //StackOverflowException shown here
}

    public int deleteTicketFestival(String festId, String typId)
    {
        int deletedRows = -1;
        try
        {
            sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["project"].ConnectionString);
            sqlCommand = new SqlCommand("DeleteTicketFestival", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlAdapter = new SqlDataAdapter(sqlCommand);

            sqlCommand.Parameters.Add(new SqlParameter("@festId", festId));
            sqlCommand.Parameters.Add(new SqlParameter("@typId", typId));

            sqlConnection.Open();
            sqlTransaction = sqlConnection.BeginTransaction();
            sqlCommand.Transaction = sqlTransaction;
            deletedRows = sqlCommand.ExecuteNonQuery();
            sqlTransaction.Commit();
        }
        catch (Exception e)
        {
            LoggingService.WriteLine(strApplicationName + " Delete festival ticket", e.Message);
            if (sqlTransaction != null)
            {
                sqlTransaction.Rollback();
                throw (e);
            }
        }
        return deletedRows;
    }

也许有更多经验的人可以发现问题?谢谢!

4

2 回答 2

2
public int Festivals_DeleteTicketFestival(String festId, String typId)
{
    return Festivals_DeleteTicketFestival(festId, typId); //StackOverflowException shown here
}

您在没有结束条件的情况下递归调用相同的函数(实际上,除了在函数中进行此递归调用之外,您什么都不做)。这将导致 StackOverflowException。

如果您将其更改为

return deleteTicketFestival(festID, TypID)

应该解决您涉及此错误的问题。

于 2013-05-20T16:16:41.780 回答
1

您正在递归调用自己,更改return Festivals_DeleteTicketFestival(festId, typId);return deleteTicketFestival(fastId, typId);

于 2013-05-20T16:08:52.460 回答