giasone777
Active member
- Joined
- Jul 19, 2019
- Messages
- 29
- Programming Experience
- 1-3
Hello,
I would like to send multiple queries to an sql server. It works for one but I am trying to make it work for multiple values stored in an array which came from multiple selections from a listbox.
So right now @RealVms is determining the query, so for instance I would like that query to pull the values from within the array gotselections[num] so it would basically have the following effect
Please help - Thank-you in advance. Jason.
These are VMware objects stored in an sql database. At the end the query is sent to an asp grid. The following code does work but for only one query.
I would like to send multiple queries to an sql server. It works for one but I am trying to make it work for multiple values stored in an array which came from multiple selections from a listbox.
So right now @RealVms is determining the query, so for instance I would like that query to pull the values from within the array gotselections[num] so it would basically have the following effect
string selectSql = ("select Name, vmHost, Uid from db_owner.vms where UID Like @gotselections[0] and where UID like @gotselections[1] ");
or higher depending on the number of selections from the listbox.Please help - Thank-you in advance. Jason.
These are VMware objects stored in an sql database. At the end the query is sent to an asp grid. The following code does work but for only one query.
C#:
string hosty = vmtofind.Text;
String GetSelection = objectList.SelectedItem.Text;
string RealVms = "%" + GetSelection + "%";
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString))
{
con.Open();
string selectSql = ("select Name, vmHost, Uid from db_owner.vms where UID Like @RealVms");
SqlCommand cmd = new SqlCommand(selectSql, con);
cmd.Parameters.AddWithValue("@RealVms", RealVms);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
Last edited by a moderator: