sql server - Asp.Net How to pass multiple value to a parameter which is using with 'IN' clause in the query -


I have created a web form and in the web form, there is a multilevel dropdown list. I am getting the price from the Multislate dropdown list and it is passing in the hidden area. So I'm adding the value of the hidden area to SqlCommand as a parameter. Since it is understood that I have a query and the parameter is experimenting with the 'IN' segment in the query.

When I select only one option, it is working smoothly and I can get a dataset. But when this is chosen multi.it is not returning any results.

Question: Select

  ... from tbl reservation where type IN (@type)  

code:

  command.Parameters.Add (new SqlParameter ("Type", hidden field .VIL));  

When an option is selected the hidden area. Value = "Flight"

When multiple options are selected HiddenField.Value = "Flight, Hotel, Renter"

SQL Server looks at your IN section:

  IN ('flight, hotel, rentals')  

What do you want

  IN ('flight', 'hotel', 'rent')  

A parameter is required.

You can use this approach:

  string [] type = HiddenField.Value. Split (','); // {"flight", "hotel", "hirer"}; String cmdText = "SELECT * FROM tblRervationWhere type IN ({0})"; String [] paramNames = types.Select ((s, i) = & gt; "@type" + i.ToString ()) .ToArray (); String inClause = string.Join (",", nickname); {Int (ii = 0; i & lt; paramNames.Length; i ++) for {SqlCommand cmd = new SqlCommand (string.Format (cmdText, inClause))} {cmd.Parameters.AddWithValue (common name [i], Type [i]); }}  

Reference:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -