3

I am filtering the data of an SQL data source by setting a WHERE clause parameter in this formatting [@a] and in the event of a combo box, I would to set the value to this parameter, the previous sql data source for a gridview

SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectParameters["@a"].DefaultValue = cid.ToString();
SqlDataSource2.DataBind();

I need to pass value to the WHERE parameter.

I choose the filtering parsed on non choice ( not form or control or profile or session ...)

This way gives me an error. Is there any way to give a value for this parameter [@a]?

1 Answer 1

2

Try the following:

ASPX:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" 
                   ConnectionString="<%$ConnectionStrings:MyConnectionString %>" 
                   SelectCommandType="Text"
                   SelectCommand = "SELECT * FROM TABLE WHERE a=@a"  
                   CancelSelectOnNullParameter="false"> 
        <SelectParameters>
            <asp:QueryStringParameter Name="a" QueryStringField="a" 
                           DbType="String" ConvertEmptyStringToNull="true" />
              </SelectParameters>
</asp:SqlDataSource> 

C# Code-Behind:

change @a to a:

SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectParameters["a"].DefaultValue = cid.ToString();
SqlDataSource2.DataBind();

If @a is the FIRST parameter you can also set it using INDEX 0:

SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectParameters[0].DefaultValue = cid.ToString();
SqlDataSource2.DataBind();
Sign up to request clarification or add additional context in comments.

Comments

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.