1

I am adding a parameter through Querystring. My code is:

 SqlCommand Cmd = new SqlCommand("Showvillage", Constr1);
        Cmd.CommandType = CommandType.StoredProcedure;
        Cmd.Parameters.Add("@Yojna_No", Request.QueryString[0]);
        Cmd.Parameters.Add("@Village_Code", Request.QueryString[1]);
        DataSet ds = new DataSet();

Now due to my requirement i have to send multiple value for each parameter and the multiple value is coming as Session array from previous page.Can anyone solve how to add that session array to parameter

 SqlCommand Cmd = new SqlCommand("Showvillage", Constr1);
        Cmd.CommandType = CommandType.StoredProcedure;
        string[] getyojna = (string[])Session["value"];
        string[] getvillage = (string[])Session["values"];
        Cmd.Parameters.Add("@Yojna_No", Request.QueryString[0]);//change here for session
        Cmd.Parameters.Add("@Village_Code", Request.QueryString[1]);//change here for session
1

2 Answers 2

2
 SqlParameter something = new SqlParameter("parameterName", "value");
     SqlParameter something2 = new SqlParameter("parameterName2", "value2");
    SqlParameterCollection parameters=new SqlParameterCollection();
    parameters.Add(something);
    parameters.Add(something2);

Maybe you should use something like this.

Sign up to request clarification or add additional context in comments.

Comments

1

If you have successully assigned the session object Session["values"] to getvillage string array then you can simply use index of string array (getvillage) to get elements.

Cmd.Parameters.Add("@Yojna_No", getvillage[0]);
Cmd.Parameters.Add("@Village_Code", getvillage[1]);

3 Comments

what if i need to send multiple value. So i have to use for loop again.
'int count = vill.Rows.Count; string[] ar = new string[count]; for (int i = 0; i < vill.Rows.Count; i++) { string yojna=vill.Rows[i]["YojnaNo"].ToString(); ar[i] = yojna;} Session["value"] = ar;' this is my code to add array in session can u check it too
Where you have this loop ? as I could not see in question

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.