Can nyone tell me how to relatr combo boxes????
i hv used this code bt this is throwing exception ......ny help would be appreciated .I hv jst started wworking on c#


i hv used the following code nd i hv populated the cmbschoolcode in loading of my form

private void cmbSchCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            String connectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
           

            DataTable dt = new DataTable();
            string Query = String.Format(@"SELECT RegNo FROM Student WHERE SchoolCode ={0} ", cmbSchCode.Text);
            OleDbDataAdapter adapter = new OleDbDataAdapter(Query,connectionString);
           
            adapter.Fill(dt);

           

           foreach (DataRow dr in dt.Rows)
            {
                cmbStudent.Items.Add(dr[0].ToString());
            }
           
           
        }

its saying no value given to one or more parameters .

Recommended Answers

All 6 Replies

i think it requires ' ' around {0} to distinguish it from an SQL variable

i think it requires ' ' around {0} to distinguish it from an SQL variable

thanx mahn it really worked bt still one problem is dre that the value from student combo box is not going in the database.....

yes but your query is a select query, to insert something into database you should run insert query which i dont see in your code.

yes but your query is a select query, to insert something into database you should run insert query which i dont see in your code.

i hv inserted the insert query after my code but is shows exception that it will create duplicate values.i hv also tried the update query bt it also doen'nt work.....

I hv inserted the insert query at the press of save button .....
every thing else is working but the value of student combo box is not going in the database.....plz nyone help meee

leave it it is solved there was some problem in my query..
thank you very much for helping me...I am really grateful to you..
Could you help me on the other thread i am having another problem in my code...I would be really gratefull to you....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.