0

I keep getting the error, Must declare the scalar variable "@inspIdFk" when attempting to use the following:

protected void rgInspections_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (GridDataItem item in rgInspections.SelectedItems)
        {
            hdn_insp_id_pk.Value = item["inspIdPk"].Text;
        }

        string inspidvalue = hdn_insp_id_pk.Value;

        if (HttpContext.Current.User.IsInRole("AKOB") || (HttpContext.Current.User.IsInRole("aMgr")))
        {
            SqlDataSource sdcRgActExps2 = new SqlDataSource();
            sdcRgActExps2.ID = "sdcRgActExps2";
            this.Page.Controls.Add(sdcRgActExps2);
            sdcRgActExps2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            sdcRgActExps2.SelectCommand = "SELECT ae.actExpIdPk, ae.inspIdFk, ae.actExpDt, aet.actExpType, ae.actExpQty, ae.actExpRate, ae.actExpBill, (ae.actExpQty * ae.actExpRate) AS subTotal FROM inspActExps ae LEFT JOIN actExpTypes aet ON ae.actExpType = aet.actExpTypeIdPk WHERE ([inspIdFk] = @inspIdFk) AND actExpSecCd = 1 ORDER BY actExpDt";
            sdcRgActExps2.SelectParameters.Add("@inspIdFk", inspidvalue);
            rgActExps2.DataSource = sdcRgActExps2;
            rgActExps2.DataBind();
        }
        else
        { 
            ...
        }
    }

How can I successfully set the value of @inspIdFk? I verified that the query does pull data by removing inspIdFk = @inspIdFk from the WHERE clause.

1 Answer 1

2

As I understand it, SqlDataSource.SelectParameters.Add takes a parameter name without an ampersand, so your add should look like this:

sdcRgActExps2.SelectParameters.Add("inspIdFk", inspidvalue);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for such a quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.