0
votes

Can someone tell me where I'm going wrong here?

I have this SQL code:

ALTER PROCEDURE [site].[GetJobs] 
    @Locale char(2) = NULL
   ,@jid INT = NULL
   ,@limit INT = 10000
AS
BEGIN
    SET NOCOUNT ON;

    SELECT TOP (@limit)
        JO.PrimaryKeyID
        ,coalesce(GT.translation, JO.Title) As Title
        ,coalesce(GT3.translation, JO.LongDescription) As LongDescription
        ,coalesce(GT5.translation, JO.Experience) As Experience
        ,JO.Image
        ,JO.ClosingDate
        ,JO.OrderIndex
        ,JO.Active
    FROM 
        [Jobs] JO
    LEFT JOIN 
        ln_GenericTranslations GT ON GT.DbTable = 'Jobs' 
        AND GT.dbfield = 'Title' and GT.DBRecordID = JO.PrimaryKeyID AND GT.locale like @Locale
    LEFT JOIN 
        ln_GenericTranslations GT3 ON GT3.DbTable = 'Jobs' 
        AND GT3.dbfield = 'LongDescription' and GT3.DBRecordID = JO.PrimaryKeyID AND GT3.locale like @Locale
    LEFT JOIN 
        ln_GenericTranslations GT5 ON GT5.DbTable = 'Jobs' 
        AND GT5.dbfield = 'Experience' and GT5.DBRecordID = JO.PrimaryKeyID AND GT5.locale like @Locale
    WHERE 
        JO.Active = 1
        AND (JO.PrimaryKeyID = @jid OR @jid IS NULL)
        AND ((DATEDIFF(dd,GetDate(), JO.ClosingDate) >= 0) OR JO.ClosingDate IS NULL)
    ORDER BY 
        JO.ClosingDate DESC, JO.PrimaryKeyID DESC
END
GO

I have it linked up to a repeater however when I run the page it gives me this error:

Error in Visual Studio

Does anyone know why this is occurring? I've looked up similar answer but none that seem to help me! All I know is the exact same stored procedure has been used before and it worked fine?

If you need any added info let me know!

Added Repeater code:

<Engine:WidgetSQLDataSource ID="DS_Jobs" runat="server" SelectCommand="site.GetJobs" />
 <asp:Repeater ID="rp_jobs_list" runat="server" DataSourceID="DS_Jobs">
            <HeaderTemplate>
                <div class="jobs jobs_list span6">
            </HeaderTemplate>
            <ItemTemplate>
                <div class="item">
                    <asp:HyperLink ID="HyperLink1" runat="server" Visible='<%#!string.IsNullOrEmpty((string)Eval("Image"))%>'
                        NavigateUrl='<%#  CommonFunctions.GetTreeURL(Convert.ToInt32(Resources.Pages.Jobs), "jid=" + Eval("PrimaryKeyID"))%>'><img src="/uploads/images<%#Eval("Image")%>" alt="<%# Eval("Title") %>" /></asp:HyperLink>

                    <h2><%# Eval("Title") %></h2>
                    <p><%# CommonFunctions.StripHTML(Eval("LongDescription").ToString(), 200) %></p>
                    <a href="<%#CommonFunctions.GetTreeURL(Convert.ToInt32(Resources.Pages.Jobs), "jid=" + Eval("PrimaryKeyID"))%>" class="button button_view"><%= Resources.Text.More %></a>
                </div>
            </ItemTemplate>
            <FooterTemplate>
                </div></div></div>
        </FooterTemplate>
    </asp:Repeater>

     <% if (rp_jobs_list.Items.Count == 0 && Request.QueryString["jid"] == null) { Response.Write("There are currently no items in this section."); } %>

Backend:

protected void Page_Init(object sender, EventArgs e)
    {
        DS_Jobs.SelectParameters.Add("Locale", System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToString());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["jid"] == null)
        {
            rp_jobs_detail.Visible = false;
        }
        else
        {
            DS_Jobs.SelectParameters.Add("jid", Request.QueryString["jid"]);
            rp_jobs_list.Visible = false;
        }
    }
2
Can you show the repeater code? I assume you set more than 3 parameters. - Der_Meister
Added code calling the sproc and repeater. I'll have a look at clearing parameters! - T.J. Wallace

2 Answers

0
votes

Where do you add the limit parameter? That is not defined here. Also, on page postbacks, these parameters may not be persisted on the server, and thus you would need to recreate them.

0
votes

I'm guessing the previous parameters were not cleared from DS_Jobs.SelectParameters and are being carried over somehow, resulting in "jid" being added multiple times.

You could try modifying your code to clear the parameters first, then re-add them all:

protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["jid"] == null)
    {
        rp_jobs_detail.Visible = false;
    }
    else
    {
        DS_Jobs.SelectParameters.Clear();
        DS_Jobs.SelectParameters.Add("Locale", System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToString());
        DS_Jobs.SelectParameters.Add("jid", Request.QueryString["jid"]);
        DS_Jobs.SelectParameters.Add("limit", /* what's the limit? */ );

        rp_jobs_list.Visible = false;
    }
}