To put it into short story
i wanted something like "SELECT companyName FROM table where mainCategory = firstcombobox and subcategory = secondcombobox" , how do i do the sql query?
To put it into Long story.
I have created a form , with a working coding , but i need an extra assistance.
Somewhat , i am stuck on trying to figure out how to let the 3rd combobox value , determined by the first and second.
and what i wanted is , something like , getting the value of Main Category and Sub category to effect the list of the third combo box.
and then shows the company name within the picks of main and sub category.
Like this : *links and images are disabled at the moment*
For the Main Category and Sub-Category , i have it working with this code.
This code also includes the 3rd ComboBox code which right now operates without the first and second combobox attached to the 3rd combobox code. (meaning that it operates manually , but did not have the main category and sub category filter.)
*links and images are disabled at the moment*
*links and images are disabled at the moment*
and the code for the `View Selected Company` `button` is :
So , how do i do it?
i wanted something like "SELECT companyName FROM table where mainCategory = firstcombobox and subcategory = secondcombobox" , how do i do the sql query?
To put it into Long story.
I have created a form , with a working coding , but i need an extra assistance.
Somewhat , i am stuck on trying to figure out how to let the 3rd combobox value , determined by the first and second.
and what i wanted is , something like , getting the value of Main Category and Sub category to effect the list of the third combo box.
and then shows the company name within the picks of main and sub category.
Like this : *links and images are disabled at the moment*
For the Main Category and Sub-Category , i have it working with this code.
This code also includes the 3rd ComboBox code which right now operates without the first and second combobox attached to the 3rd combobox code. (meaning that it operates manually , but did not have the main category and sub category filter.)
public partial class User : Form { Dictionary<string, List<string>> Category = new Dictionary<string, List<string>>(); DataSet ds1; public User() { InitializeComponent(); } private void User_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"; conn.Open(); SqlDataAdapter daMain = new SqlDataAdapter("SELECT * FROM MAINCATE", conn); ds1 = new DataSet(); daMain.Fill(ds1, "Maincate"); DataTable dt = ds1.Tables["MAINCATE"]; foreach (DataRow dr in dt.Rows) { List<string> SubCats = new List<string> { dr["Subcat1"].ToString(), dr["Subcat2"].ToString(), dr["Subcat3"].ToString(), dr["Subcat4"].ToString() }; Category.Add(dr["mainCate"].ToString(), SubCats); mainCatU.Items.Add(dr["mainCate"].ToString()); } mainCatU.DropDownStyle = ComboBoxStyle.DropDownList; mainCatU.Enabled = true; subCatU.DropDownStyle = ComboBoxStyle.DropDownList; //**Code for third combobox** SqlDataAdapter daSearch = new SqlDataAdapter("SELECT cName FROM ComDet", conn); DataTable dt1 = new DataTable(); ListU.DataSource = dt1; daSearch.Fill(dt1); ListU.ValueMember = "cName"; ListU.DisplayMember = "cName"; ListU.DropDownStyle = ComboBoxStyle.DropDownList; ListU.Enabled = true; //**----------------------** conn.Close(); } private void mainCatU_SelectedIndexChanged(object sender, EventArgs e) { if(Category.ContainsKey(mainCatU.SelectedItem.ToString())) { subCatU.DataSource = Category[mainCatU.SelectedItem.ToString()]; } }and the databases are as shown :
*links and images are disabled at the moment*
*links and images are disabled at the moment*
and the code for the `View Selected Company` `button` is :
private void searchBtn_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=PEWPEWDIEPIE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"; conn.Open(); SqlDataAdapter daS = new SqlDataAdapter("select cName, cDetails, cDetails2 from ComDet where cName = @cName", conn); daS.SelectCommand.Parameters.Add("@cName", SqlDbType.VarChar).Value = ListU.SelectedValue; DataTable dts3 = new DataTable(); daS.Fill(dts3); dataGridView1.DataSource = dts3.DefaultView; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; conn.Close(); }* again , right now the third combo box is coded to run without the maincategory and subcategory
So , how do i do it?