Is there a way to pick up ID after cascading multiple combobox without using ID as value member of combobox?cascading comboBox in windows form using c#fill textbox on second combobox selection changed in cascading combobox in windows form using c#How do I insert multiple rows WITHOUT repeating the “INSERT INTO dbo.Blah” part of the statement?ComboBox: Adding Text and Value to an Item (no Binding Source)don't see the new database and can't log inExporting Large Amounts of DataCombobox Value Member to currencyProper way to initialize a C# dictionary with values?Using ExpandoObject with ComboBox Items not picking up Display and Value membersCascading Combobox - WinForms with added valuesCombobox show value memberCase query sql command in asp.net webform

How to prevent cables getting intertwined

Have Steve Rogers (Captain America) and a young Erik Lehnsherr (Magneto) interacted during WWII?

How to know whether to write accidentals as sharps or flats?

Can a non-invertible function be inverted by returning a set of all possible solutions?

Print the phrase "And she said, 'But that's his.'" using only the alphabet

What is the color associated with lukewarm?

Do my partner and son need an SSN to be dependents on my taxes?

What is this plant I saw for sale at a Romanian farmer's market?

How to search for Android apps without ads?

Why is gun control associated with the socially liberal Democratic party?

Why is Skinner so awkward in Hot Fuzz?

How can the US president give an order to a civilian?

How can this shape perfectly cover a cube?

Digital signature that is only verifiable by one specific person

What kind of chart is this?

How to sort human readable size

What are the mechanical differences between Adapt and Monstrosity?

Why can't we feel the Earth's revolution?

I have found ports on my Samsung smart tv running a display service. What can I do with it?

Co-worker is now managing my team. Does this mean that I'm being demoted?

How did the European Union reach the figure of 3% as a maximum allowed deficit?

How can I maintain game balance while allowing my player to craft genuinely useful items?

Are there any super-powered aliens in the Marvel universe?

100-doors puzzle



Is there a way to pick up ID after cascading multiple combobox without using ID as value member of combobox?


cascading comboBox in windows form using c#fill textbox on second combobox selection changed in cascading combobox in windows form using c#How do I insert multiple rows WITHOUT repeating the “INSERT INTO dbo.Blah” part of the statement?ComboBox: Adding Text and Value to an Item (no Binding Source)don't see the new database and can't log inExporting Large Amounts of DataCombobox Value Member to currencyProper way to initialize a C# dictionary with values?Using ExpandoObject with ComboBox Items not picking up Display and Value membersCascading Combobox - WinForms with added valuesCombobox show value memberCase query sql command in asp.net webform






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I need to get productID from product table and pass it to a textbox. But I want to select the product ID by cascading comboBox texts as SQL query parameters.



I have tried cascading the comboBoxes. The cascading works fine and displays what I need.



I have done some research in cascading comboBox. Here are two useful links I have found out.



cascading comboBox in windows form using c#



fill textbox on second combobox selection changed in cascading combobox in windows form using c#



In both links I did not find answer to my question.



Here is a demo table



ProductID Category SubCategory Item
--------- ------------------------------ -------------------- ----------------
1 Pen Ballpoint Matadoor
2 Pencil HB Natraz


I want get ProductID values by selecting Category, SubCategory, Item using cascaded comboBoxes.



Here is some demo code that takes care of the cascading.



1st ComboBox:



public InventroyAddForm()


InitializeComponent();
string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product";
string query2 = "select * from PartySpecificPrice";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com = new SqlCommand(query1, con);
//con.Open();
SqlDataAdapter adp = new SqlDataAdapter(com);
DataTable dt = new DataTable();
adp.Fill(dt);
comboBox2.ValueMember = "Category";
comboBox2.DisplayMember = "Category";
comboBox2.DataSource = dt;
//con.Close();
comboBox3.Enabled = false;
comboBox4.Enabled = false;




2nd ComboBox:



private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

if(comboBox2.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com1 = new SqlCommand(query1, con);
//con.Open();
com1.Parameters.AddWithValue("@Category",comboBox2.SelectedValue.ToString());
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox3.ValueMember = "Category";
comboBox3.DisplayMember = "SubCategory";
comboBox3.DataSource = dt1;
comboBox3.Enabled = true;
comboBox4.Enabled = false;
//con.Close();




3rd ComboBox:



private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox3.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query2 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com2 = new SqlCommand(query2, con);
//con.Open();
com2.Parameters.AddWithValue("@Category", comboBox3.SelectedValue.ToString());
SqlDataAdapter adp2 = new SqlDataAdapter(com2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
comboBox4.ValueMember = "Category";
comboBox4.DisplayMember = "Item";
comboBox4.DataSource = dt2;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
//con.Close();
textBox2.Text = Convert.ToString(comboBox3.SelectedIndex);











share|improve this question

















  • 1





    if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

    – vikscool
    Mar 25 at 4:36












  • I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

    – Khandkar Asif Hossain
    Mar 25 at 12:07







  • 1





    Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

    – vikscool
    Mar 27 at 4:10







  • 1





    2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

    – vikscool
    Mar 27 at 4:12











  • Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

    – Khandkar Asif Hossain
    Mar 28 at 8:34


















0















I need to get productID from product table and pass it to a textbox. But I want to select the product ID by cascading comboBox texts as SQL query parameters.



I have tried cascading the comboBoxes. The cascading works fine and displays what I need.



I have done some research in cascading comboBox. Here are two useful links I have found out.



cascading comboBox in windows form using c#



fill textbox on second combobox selection changed in cascading combobox in windows form using c#



In both links I did not find answer to my question.



Here is a demo table



ProductID Category SubCategory Item
--------- ------------------------------ -------------------- ----------------
1 Pen Ballpoint Matadoor
2 Pencil HB Natraz


I want get ProductID values by selecting Category, SubCategory, Item using cascaded comboBoxes.



Here is some demo code that takes care of the cascading.



1st ComboBox:



public InventroyAddForm()


InitializeComponent();
string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product";
string query2 = "select * from PartySpecificPrice";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com = new SqlCommand(query1, con);
//con.Open();
SqlDataAdapter adp = new SqlDataAdapter(com);
DataTable dt = new DataTable();
adp.Fill(dt);
comboBox2.ValueMember = "Category";
comboBox2.DisplayMember = "Category";
comboBox2.DataSource = dt;
//con.Close();
comboBox3.Enabled = false;
comboBox4.Enabled = false;




2nd ComboBox:



private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

if(comboBox2.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com1 = new SqlCommand(query1, con);
//con.Open();
com1.Parameters.AddWithValue("@Category",comboBox2.SelectedValue.ToString());
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox3.ValueMember = "Category";
comboBox3.DisplayMember = "SubCategory";
comboBox3.DataSource = dt1;
comboBox3.Enabled = true;
comboBox4.Enabled = false;
//con.Close();




3rd ComboBox:



private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox3.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query2 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com2 = new SqlCommand(query2, con);
//con.Open();
com2.Parameters.AddWithValue("@Category", comboBox3.SelectedValue.ToString());
SqlDataAdapter adp2 = new SqlDataAdapter(com2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
comboBox4.ValueMember = "Category";
comboBox4.DisplayMember = "Item";
comboBox4.DataSource = dt2;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
//con.Close();
textBox2.Text = Convert.ToString(comboBox3.SelectedIndex);











share|improve this question

















  • 1





    if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

    – vikscool
    Mar 25 at 4:36












  • I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

    – Khandkar Asif Hossain
    Mar 25 at 12:07







  • 1





    Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

    – vikscool
    Mar 27 at 4:10







  • 1





    2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

    – vikscool
    Mar 27 at 4:12











  • Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

    – Khandkar Asif Hossain
    Mar 28 at 8:34














0












0








0








I need to get productID from product table and pass it to a textbox. But I want to select the product ID by cascading comboBox texts as SQL query parameters.



I have tried cascading the comboBoxes. The cascading works fine and displays what I need.



I have done some research in cascading comboBox. Here are two useful links I have found out.



cascading comboBox in windows form using c#



fill textbox on second combobox selection changed in cascading combobox in windows form using c#



In both links I did not find answer to my question.



Here is a demo table



ProductID Category SubCategory Item
--------- ------------------------------ -------------------- ----------------
1 Pen Ballpoint Matadoor
2 Pencil HB Natraz


I want get ProductID values by selecting Category, SubCategory, Item using cascaded comboBoxes.



Here is some demo code that takes care of the cascading.



1st ComboBox:



public InventroyAddForm()


InitializeComponent();
string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product";
string query2 = "select * from PartySpecificPrice";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com = new SqlCommand(query1, con);
//con.Open();
SqlDataAdapter adp = new SqlDataAdapter(com);
DataTable dt = new DataTable();
adp.Fill(dt);
comboBox2.ValueMember = "Category";
comboBox2.DisplayMember = "Category";
comboBox2.DataSource = dt;
//con.Close();
comboBox3.Enabled = false;
comboBox4.Enabled = false;




2nd ComboBox:



private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

if(comboBox2.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com1 = new SqlCommand(query1, con);
//con.Open();
com1.Parameters.AddWithValue("@Category",comboBox2.SelectedValue.ToString());
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox3.ValueMember = "Category";
comboBox3.DisplayMember = "SubCategory";
comboBox3.DataSource = dt1;
comboBox3.Enabled = true;
comboBox4.Enabled = false;
//con.Close();




3rd ComboBox:



private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox3.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query2 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com2 = new SqlCommand(query2, con);
//con.Open();
com2.Parameters.AddWithValue("@Category", comboBox3.SelectedValue.ToString());
SqlDataAdapter adp2 = new SqlDataAdapter(com2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
comboBox4.ValueMember = "Category";
comboBox4.DisplayMember = "Item";
comboBox4.DataSource = dt2;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
//con.Close();
textBox2.Text = Convert.ToString(comboBox3.SelectedIndex);











share|improve this question














I need to get productID from product table and pass it to a textbox. But I want to select the product ID by cascading comboBox texts as SQL query parameters.



I have tried cascading the comboBoxes. The cascading works fine and displays what I need.



I have done some research in cascading comboBox. Here are two useful links I have found out.



cascading comboBox in windows form using c#



fill textbox on second combobox selection changed in cascading combobox in windows form using c#



In both links I did not find answer to my question.



Here is a demo table



ProductID Category SubCategory Item
--------- ------------------------------ -------------------- ----------------
1 Pen Ballpoint Matadoor
2 Pencil HB Natraz


I want get ProductID values by selecting Category, SubCategory, Item using cascaded comboBoxes.



Here is some demo code that takes care of the cascading.



1st ComboBox:



public InventroyAddForm()


InitializeComponent();
string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product";
string query2 = "select * from PartySpecificPrice";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com = new SqlCommand(query1, con);
//con.Open();
SqlDataAdapter adp = new SqlDataAdapter(com);
DataTable dt = new DataTable();
adp.Fill(dt);
comboBox2.ValueMember = "Category";
comboBox2.DisplayMember = "Category";
comboBox2.DataSource = dt;
//con.Close();
comboBox3.Enabled = false;
comboBox4.Enabled = false;




2nd ComboBox:



private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

if(comboBox2.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query1 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com1 = new SqlCommand(query1, con);
//con.Open();
com1.Parameters.AddWithValue("@Category",comboBox2.SelectedValue.ToString());
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox3.ValueMember = "Category";
comboBox3.DisplayMember = "SubCategory";
comboBox3.DataSource = dt1;
comboBox3.Enabled = true;
comboBox4.Enabled = false;
//con.Close();




3rd ComboBox:



private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox3.SelectedValue.ToString() != null)

string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string query2 = "select * from Product where Category=@Category";
SqlConnection con = new SqlConnection(maincon);
SqlCommand com2 = new SqlCommand(query2, con);
//con.Open();
com2.Parameters.AddWithValue("@Category", comboBox3.SelectedValue.ToString());
SqlDataAdapter adp2 = new SqlDataAdapter(com2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
comboBox4.ValueMember = "Category";
comboBox4.DisplayMember = "Item";
comboBox4.DataSource = dt2;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
//con.Close();
textBox2.Text = Convert.ToString(comboBox3.SelectedIndex);








c# sql-server winforms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 4:10









Khandkar Asif HossainKhandkar Asif Hossain

507




507







  • 1





    if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

    – vikscool
    Mar 25 at 4:36












  • I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

    – Khandkar Asif Hossain
    Mar 25 at 12:07







  • 1





    Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

    – vikscool
    Mar 27 at 4:10







  • 1





    2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

    – vikscool
    Mar 27 at 4:12











  • Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

    – Khandkar Asif Hossain
    Mar 28 at 8:34













  • 1





    if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

    – vikscool
    Mar 25 at 4:36












  • I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

    – Khandkar Asif Hossain
    Mar 25 at 12:07







  • 1





    Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

    – vikscool
    Mar 27 at 4:10







  • 1





    2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

    – vikscool
    Mar 27 at 4:12











  • Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

    – Khandkar Asif Hossain
    Mar 28 at 8:34








1




1





if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

– vikscool
Mar 25 at 4:36






if you are going to deal with strings(which I would not recommend) then why not create another query to fetch the ProductID from the product table with a where condition of Category=<SomeCategoryValue> and SubCategory=<SomeSubCategoryValue> and Item=<SomeItemValue>;

– vikscool
Mar 25 at 4:36














I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

– Khandkar Asif Hossain
Mar 25 at 12:07






I would have but I need to fetch the ProductID and Products table will have a large number of data with many categories, subcategories and items. To offer a simpler way to select the ProductID cascading comboBox is the way to go in my opinion. Because to use your suggested query I have use either exact or approximate(using wildcards) SQL parameters value which is quite hard to do where the database has lots of products.I would like to hear about your recommendation about not using strings @vikscool

– Khandkar Asif Hossain
Mar 25 at 12:07





1




1





Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

– vikscool
Mar 27 at 4:10






Sorry for the delayed response,1st As for why I would not recommend the String? What if you have two items with the same name in different subcategories and the way you are getting the items it would be hard for you to identify which item belongs to which subcategory(as your query is based on Category and not Category+SubCategory).

– vikscool
Mar 27 at 4:10





1




1





2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

– vikscool
Mar 27 at 4:12





2nd Your demo table looks like its a Joined Result. So, if you have other master tables for Category and SubCategory, it would be easier to make the cascading where the item table will have its parent SubCategoryId and the SubCategory would have its parent CategoryId. Hence, the relation would become something like this: Category->get SubCategory based on the categoryId->get Items based on the subcategoryId.

– vikscool
Mar 27 at 4:12













Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

– Khandkar Asif Hossain
Mar 28 at 8:34






Thanks @vikscool. First of all your assumption of the table being join table is incorrect. The table i provided is in fact a single table. And you are suggesting to break up the table. But can I retrieve the product ID if I break up the table? if so can you post an answer based on your suggestion.

– Khandkar Asif Hossain
Mar 28 at 8:34













1 Answer
1






active

oldest

votes


















0














Based on @vikschool comments. I have broken up the tables as follows:



CID Category
----------- --------------------------------------------------
1 Pen
2 Pencil


SID CID SubCategory
----------- ----------- --------------------------------------------------
1 1 BallPoint
2 2 HB


ID SID CID Item
----------- ----------- ----------- --------------------------------------------------
1 1 1 Matadoor
2 2 2 Natraz


Category SubCategory Item
-------------- -------------------------------------------------- -----------------------
Pen BallPoint Matadoor
Pencil HB Natraz


Here is the code that worked for me.



FormLoad:



private void Form1_Load(object sender, EventArgs e)

string query2 = "select * from Category";
string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
SqlCommand com1 = new SqlCommand(query2, con);
con.Open();
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox1.ValueMember = "CID";
comboBox1.DisplayMember = "Category";
comboBox1.DataSource = dt1;
comboBox3.Enabled = false;
comboBox2.Enabled = false;




First ComboBox:



private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox1.SelectedValue != null)


string query2 = "select * from SubCategory where CID=@CID";
SqlCommand com1 = new SqlCommand(query2, con);
com1.Parameters.AddWithValue("@CID", comboBox1.SelectedValue);
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox2.ValueMember = "SID";
comboBox2.DisplayMember = "SubCategory";
comboBox2.DataSource = dt1;
comboBox3.Enabled = false;
comboBox2.Enabled = true;





Second ComboBox:



private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

if (comboBox2.SelectedValue != null)

string query2 = "select * from Item where SID=@ID";
SqlCommand com1 = new SqlCommand(query2, con);
com1.Parameters.AddWithValue("@SID", comboBox2.SelectedValue);
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
comboBox3.ValueMember = "ID";
comboBox3.DisplayMember = "Item";
comboBox3.DataSource = dt1;
con.Close();
comboBox3.Enabled = true;
comboBox2.Enabled = true;




Third ComboBox:



private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

textBox1.Text = Convert.ToString(comboBox3.SelectedValue);



Note: I have tried this with Access database. Sql should work with above code. Please let me know if anyone find any problem using this piece of code.
Happy Coding.
Thanks to @vikschool.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331159%2fis-there-a-way-to-pick-up-id-after-cascading-multiple-combobox-without-using-id%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Based on @vikschool comments. I have broken up the tables as follows:



    CID Category
    ----------- --------------------------------------------------
    1 Pen
    2 Pencil


    SID CID SubCategory
    ----------- ----------- --------------------------------------------------
    1 1 BallPoint
    2 2 HB


    ID SID CID Item
    ----------- ----------- ----------- --------------------------------------------------
    1 1 1 Matadoor
    2 2 2 Natraz


    Category SubCategory Item
    -------------- -------------------------------------------------- -----------------------
    Pen BallPoint Matadoor
    Pencil HB Natraz


    Here is the code that worked for me.



    FormLoad:



    private void Form1_Load(object sender, EventArgs e)

    string query2 = "select * from Category";
    string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
    SqlCommand com1 = new SqlCommand(query2, con);
    con.Open();
    SqlDataAdapter adp1 = new SqlDataAdapter(com1);
    DataTable dt1 = new DataTable();
    adp1.Fill(dt1);
    comboBox1.ValueMember = "CID";
    comboBox1.DisplayMember = "Category";
    comboBox1.DataSource = dt1;
    comboBox3.Enabled = false;
    comboBox2.Enabled = false;




    First ComboBox:



    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    if (comboBox1.SelectedValue != null)


    string query2 = "select * from SubCategory where CID=@CID";
    SqlCommand com1 = new SqlCommand(query2, con);
    com1.Parameters.AddWithValue("@CID", comboBox1.SelectedValue);
    SqlDataAdapter adp1 = new SqlDataAdapter(com1);
    DataTable dt1 = new DataTable();
    adp1.Fill(dt1);
    comboBox2.ValueMember = "SID";
    comboBox2.DisplayMember = "SubCategory";
    comboBox2.DataSource = dt1;
    comboBox3.Enabled = false;
    comboBox2.Enabled = true;





    Second ComboBox:



    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

    if (comboBox2.SelectedValue != null)

    string query2 = "select * from Item where SID=@ID";
    SqlCommand com1 = new SqlCommand(query2, con);
    com1.Parameters.AddWithValue("@SID", comboBox2.SelectedValue);
    SqlDataAdapter adp1 = new SqlDataAdapter(com1);
    DataTable dt1 = new DataTable();
    adp1.Fill(dt1);
    comboBox3.ValueMember = "ID";
    comboBox3.DisplayMember = "Item";
    comboBox3.DataSource = dt1;
    con.Close();
    comboBox3.Enabled = true;
    comboBox2.Enabled = true;




    Third ComboBox:



    private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

    textBox1.Text = Convert.ToString(comboBox3.SelectedValue);



    Note: I have tried this with Access database. Sql should work with above code. Please let me know if anyone find any problem using this piece of code.
    Happy Coding.
    Thanks to @vikschool.






    share|improve this answer



























      0














      Based on @vikschool comments. I have broken up the tables as follows:



      CID Category
      ----------- --------------------------------------------------
      1 Pen
      2 Pencil


      SID CID SubCategory
      ----------- ----------- --------------------------------------------------
      1 1 BallPoint
      2 2 HB


      ID SID CID Item
      ----------- ----------- ----------- --------------------------------------------------
      1 1 1 Matadoor
      2 2 2 Natraz


      Category SubCategory Item
      -------------- -------------------------------------------------- -----------------------
      Pen BallPoint Matadoor
      Pencil HB Natraz


      Here is the code that worked for me.



      FormLoad:



      private void Form1_Load(object sender, EventArgs e)

      string query2 = "select * from Category";
      string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
      SqlCommand com1 = new SqlCommand(query2, con);
      con.Open();
      SqlDataAdapter adp1 = new SqlDataAdapter(com1);
      DataTable dt1 = new DataTable();
      adp1.Fill(dt1);
      comboBox1.ValueMember = "CID";
      comboBox1.DisplayMember = "Category";
      comboBox1.DataSource = dt1;
      comboBox3.Enabled = false;
      comboBox2.Enabled = false;




      First ComboBox:



      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

      if (comboBox1.SelectedValue != null)


      string query2 = "select * from SubCategory where CID=@CID";
      SqlCommand com1 = new SqlCommand(query2, con);
      com1.Parameters.AddWithValue("@CID", comboBox1.SelectedValue);
      SqlDataAdapter adp1 = new SqlDataAdapter(com1);
      DataTable dt1 = new DataTable();
      adp1.Fill(dt1);
      comboBox2.ValueMember = "SID";
      comboBox2.DisplayMember = "SubCategory";
      comboBox2.DataSource = dt1;
      comboBox3.Enabled = false;
      comboBox2.Enabled = true;





      Second ComboBox:



      private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

      if (comboBox2.SelectedValue != null)

      string query2 = "select * from Item where SID=@ID";
      SqlCommand com1 = new SqlCommand(query2, con);
      com1.Parameters.AddWithValue("@SID", comboBox2.SelectedValue);
      SqlDataAdapter adp1 = new SqlDataAdapter(com1);
      DataTable dt1 = new DataTable();
      adp1.Fill(dt1);
      comboBox3.ValueMember = "ID";
      comboBox3.DisplayMember = "Item";
      comboBox3.DataSource = dt1;
      con.Close();
      comboBox3.Enabled = true;
      comboBox2.Enabled = true;




      Third ComboBox:



      private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

      textBox1.Text = Convert.ToString(comboBox3.SelectedValue);



      Note: I have tried this with Access database. Sql should work with above code. Please let me know if anyone find any problem using this piece of code.
      Happy Coding.
      Thanks to @vikschool.






      share|improve this answer

























        0












        0








        0







        Based on @vikschool comments. I have broken up the tables as follows:



        CID Category
        ----------- --------------------------------------------------
        1 Pen
        2 Pencil


        SID CID SubCategory
        ----------- ----------- --------------------------------------------------
        1 1 BallPoint
        2 2 HB


        ID SID CID Item
        ----------- ----------- ----------- --------------------------------------------------
        1 1 1 Matadoor
        2 2 2 Natraz


        Category SubCategory Item
        -------------- -------------------------------------------------- -----------------------
        Pen BallPoint Matadoor
        Pencil HB Natraz


        Here is the code that worked for me.



        FormLoad:



        private void Form1_Load(object sender, EventArgs e)

        string query2 = "select * from Category";
        string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
        SqlCommand com1 = new SqlCommand(query2, con);
        con.Open();
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox1.ValueMember = "CID";
        comboBox1.DisplayMember = "Category";
        comboBox1.DataSource = dt1;
        comboBox3.Enabled = false;
        comboBox2.Enabled = false;




        First ComboBox:



        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        if (comboBox1.SelectedValue != null)


        string query2 = "select * from SubCategory where CID=@CID";
        SqlCommand com1 = new SqlCommand(query2, con);
        com1.Parameters.AddWithValue("@CID", comboBox1.SelectedValue);
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox2.ValueMember = "SID";
        comboBox2.DisplayMember = "SubCategory";
        comboBox2.DataSource = dt1;
        comboBox3.Enabled = false;
        comboBox2.Enabled = true;





        Second ComboBox:



        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

        if (comboBox2.SelectedValue != null)

        string query2 = "select * from Item where SID=@ID";
        SqlCommand com1 = new SqlCommand(query2, con);
        com1.Parameters.AddWithValue("@SID", comboBox2.SelectedValue);
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox3.ValueMember = "ID";
        comboBox3.DisplayMember = "Item";
        comboBox3.DataSource = dt1;
        con.Close();
        comboBox3.Enabled = true;
        comboBox2.Enabled = true;




        Third ComboBox:



        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

        textBox1.Text = Convert.ToString(comboBox3.SelectedValue);



        Note: I have tried this with Access database. Sql should work with above code. Please let me know if anyone find any problem using this piece of code.
        Happy Coding.
        Thanks to @vikschool.






        share|improve this answer













        Based on @vikschool comments. I have broken up the tables as follows:



        CID Category
        ----------- --------------------------------------------------
        1 Pen
        2 Pencil


        SID CID SubCategory
        ----------- ----------- --------------------------------------------------
        1 1 BallPoint
        2 2 HB


        ID SID CID Item
        ----------- ----------- ----------- --------------------------------------------------
        1 1 1 Matadoor
        2 2 2 Natraz


        Category SubCategory Item
        -------------- -------------------------------------------------- -----------------------
        Pen BallPoint Matadoor
        Pencil HB Natraz


        Here is the code that worked for me.



        FormLoad:



        private void Form1_Load(object sender, EventArgs e)

        string query2 = "select * from Category";
        string maincon = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
        SqlCommand com1 = new SqlCommand(query2, con);
        con.Open();
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox1.ValueMember = "CID";
        comboBox1.DisplayMember = "Category";
        comboBox1.DataSource = dt1;
        comboBox3.Enabled = false;
        comboBox2.Enabled = false;




        First ComboBox:



        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        if (comboBox1.SelectedValue != null)


        string query2 = "select * from SubCategory where CID=@CID";
        SqlCommand com1 = new SqlCommand(query2, con);
        com1.Parameters.AddWithValue("@CID", comboBox1.SelectedValue);
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox2.ValueMember = "SID";
        comboBox2.DisplayMember = "SubCategory";
        comboBox2.DataSource = dt1;
        comboBox3.Enabled = false;
        comboBox2.Enabled = true;





        Second ComboBox:



        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

        if (comboBox2.SelectedValue != null)

        string query2 = "select * from Item where SID=@ID";
        SqlCommand com1 = new SqlCommand(query2, con);
        com1.Parameters.AddWithValue("@SID", comboBox2.SelectedValue);
        SqlDataAdapter adp1 = new SqlDataAdapter(com1);
        DataTable dt1 = new DataTable();
        adp1.Fill(dt1);
        comboBox3.ValueMember = "ID";
        comboBox3.DisplayMember = "Item";
        comboBox3.DataSource = dt1;
        con.Close();
        comboBox3.Enabled = true;
        comboBox2.Enabled = true;




        Third ComboBox:



        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)

        textBox1.Text = Convert.ToString(comboBox3.SelectedValue);



        Note: I have tried this with Access database. Sql should work with above code. Please let me know if anyone find any problem using this piece of code.
        Happy Coding.
        Thanks to @vikschool.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 9:19









        Khandkar Asif HossainKhandkar Asif Hossain

        507




        507





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331159%2fis-there-a-way-to-pick-up-id-after-cascading-multiple-combobox-without-using-id%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현