Quantcast
Viewing all articles
Browse latest Browse all 20

Re: dynamic Filter ( Using multiple drop down list)

Ok. after I analyzed the issue. it was not because of DataSet dataSet = null;  an error was due to the parameters that are passing from the code behind to the stored procedure do not match. stored procedure expected to have (one campaignId, one campaign name, and either single segment or multiple segments that are associated with campaingId). Here is the stored procedure variables: 

 PROCEDURE [dbo].[spx_AmountStatsReport11]
	@start				datetime = null,
	@end				datetime = null,
	@campaignId			uniqueidentifier = null,
	@campaignName		varchar(250) = null,
	@segment			varchar(50) = null


here is what I changed to make it works only when I select single segment

 protected bool GetData(DateTime start, DateTime end, string campaign)
            {
     DataSet dataSet = null;
      ....
    try
                {
                        //string c = "@campaign";
                        //string s = "@segment";
                        string @segment = "";
                        // add selected campaign
                        //c += ddlCampaigns.Items[ddlCampaigns.SelectedIndex].Value;
                        // get selected segmets
                        int[] selectedsegments = lbSegments.GetSelectedIndices();
                        // add selected segments to s
                        for (int cnt =0; cnt < selectedsegments.Length; cnt++)
                            {
                            //@segment += lbSegments.Items[selectedsegments[cnt]].Text + ",";
                           @segment += lbSegments.Items[selectedsegments[cnt]].Text;
                            }
                        // display
                        //lbSegments.Text = @segment.Trim(',');
                        lbSegments.Text = @segment;
                        selectCommand.Parameters.AddWithValue("@campaignId", this.ddlCampaigns.SelectedValue);
                        selectCommand.Parameters.AddWithValue("@campaign", DBNull.Value);
                        selectCommand.Parameters.AddWithValue(@segment, this.lbSegments.SelectedValue);

                        .......
                       dataSet = new DataSet();
                        .....
                 }
          finally {
                       dataSet.Disopose
                   }

if you notice I commented out 

//string c = "@campaign";

because always I select one campaign per agent but it could be associated with single or multiple segments. and I also commented out the line below:

//@segment += lbSegments.Items[selectedsegments[cnt]].Text + ",";

and I put instead the line below in order to match the stored procedure @segment variable which is for now accept only single value.

@segment += lbSegments.Items[selectedsegments[cnt]].Text;

now, in order to use the two lines below:

@segment += lbSegments.Items[selectedsegments[cnt]].Text + ",";
 lbSegments.Text = @segment.Trim(',');

the @segment variable that I provided above in the stored procedure has to be changed to except single or multiple values.

do you have any idea how to change the declaration of (@segment varchar(50) = null ) to accept single or multiple values that are passing from
code behind.

I really value your valuable time that your spending.

Thank you very much.



Viewing all articles
Browse latest Browse all 20

Trending Articles