Click here to Skip to main content
15,907,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two combobox i.e combo1 & combo2 for selecting class and section respectively.
i want to show subjects of that particular class and section which are selected by the given two combobox.I am retriving subjects from Access2003 database.for i did the following code section combox_selectedindexchange ...


C#
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
           String sub = ""; 
            try
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand("select subject from ClassReg where Class_name='" + comboBox3.SelectedItem + "'  ", conn);
                OleDbDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {

                  sub = Convert.ToString(rdr[0]);


                }
                
                if (sub == "")
                {
                    panel4.Hide();
                    MessageBox.Show("No subject is alocated for this class ");

                }
                else
                {
                    label8.Text = sub;

                    panel4.Show();
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
       
        }

it shows only last class subject but i want to show all the subjects of that particular class and section.i am using c#

Edit: Code formatted
Posted
Updated 17-Apr-12 19:45pm
v2
Comments
gqadirshabbir 18-Apr-12 1:38am    
Please explain the structure of the tables from which you want select the subject and section. means columns name of the tables ...
Member 8233601 18-Apr-12 1:47am    
In my Database(Schooldb) i have a table named ClassReg with columns ID(pk),Subject,Class_name,Section,Start_time,End_time.I jst wna show subjects for that particular class and section within a pannel in winform of visual studio 2008....

1 solution

"it shows only last class subject" is because you are doing this:
C#
label8.Text = sub;


From your description, you really want to do this:
C#
label8.Text += sub;
 
Share this answer
 
Comments
Member 8233601 18-Apr-12 8:50am    
can u plz tell me what visual web developer.is it part of visual studio 2010 or we have to download it seperately?
Espen Harlinn 18-Apr-12 18:01pm    
If you are using the express edition it's a separate download ...
Espen Harlinn 18-Apr-12 18:00pm    
5'ed!
[no name] 18-Apr-12 18:29pm    
Thanks
Member 8233601 20-Apr-12 3:16am    
can u tell me how to make a single column of girdview readonly.

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