Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a windows form, with a ComboBox, in C# with Mysql Database, the table name is accounthead from this table I want to populate only particular HeadName and its under all Sub HeadName, example Sales A/C and under all this Sub HeadName only
Mysql Database Table Name: accounthead
HeadCode  HeadName     UnderHead
  1      Cash                0
  2      Bank                0 
  3      Purchase A/C        2
  9      Sales A/C           7
 10      Expense A/C         5
101      Area A              9
102      Area B              9
103      Salesman 1        101
104      Salesman 2        101
105      Salesman 3        102
106      Salesman 4        102
109      Depreciation      202


What I have tried:

C#
void BindHeadName()
{   
    string ConnectionString = Properties.Settings.Default.CurConnStr;
    using (MySqlConnection con = new MySqlConnection(ConnectionString))
    {
        string query = "Select * from accounthead ORDER BY HeadName ASC";
        MySqlCommand cmd = new MySqlCommand(query, con);
        con.Open();
        MySqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            string gname = dr.GetString("HeadName");
            ComboBox.Items.Add(gname);
        }
    }
}
Posted
Updated 24-Nov-20 18:18pm
v3
Comments
Richard MacCutchan 24-Nov-20 12:38pm    
What is the problem?
KK Nizami 24-Nov-20 12:52pm    
I Want to Populate in Combobox like
HeadCode 9 and Under UnderHead 9 then
UnderHead 9 to HeadCode 101, 102
then HeadCode 101, 102 UnderHead 101 and 102
CHill60 24-Nov-20 12:39pm    
What's wrong with
string query = "Select * from accounthead WHERE HeadName NOT IN ('Purchase A/C','Expense A/C') ORDER BY HeadName ASC";
KK Nizami 24-Nov-20 12:42pm    
not only purchases and expense account, having lot of other accounts which is not shown above
CHill60 24-Nov-20 12:56pm    
So how do you identify which ones are to be excluded?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900