Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends i need to bind the value in grid view as per the Combobox selected Event..The Problem which i got nw is the value is not retrieving from an database am getting the op as combobox value pls help me... The value should retrieve from an database...

Note: The Combo box value contain the database column Names
Here is my code

C#
string a = comboBox1.SelectedItem.ToString();
string a1 = comboBox2.SelectedItem.ToString();

groupBox3.Visible = true;
da = new SqlDataAdapter("select '" + a + "','" + a1 + "' from probablitystate1 ", cn.con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;


Thnak You...
:-)
Posted
Updated 14-Jul-13 20:15pm
v4
Comments
berrymaria 15-Jul-13 2:18am    
Is the table source of the combox1 and combobox2 is probablitystate1 ?
usha C 15-Jul-13 2:22am    
Yes ...the probablitystate1 is an table name and combox1 and combobox2 contains the field name in tat particular table
berrymaria 15-Jul-13 2:26am    
Why there is single quote in your query?
Try to use this.
da = new SqlDataAdapter("select " + a + "," + a1 + " from probablitystate1 ", cn.con);
usha C 15-Jul-13 2:27am    
Ya i done mistake thnk u got op nw chimcham thnks lot....
berrymaria 15-Jul-13 2:29am    
:) great!

Hi
Please remove the single quotes from the query and try.

C#
string a = comboBox1.SelectedItem.ToString();
 string a1 = comboBox2.SelectedItem.ToString();

 groupBox3.Visible = true;
 da = new SqlDataAdapter("select " + a + "," + a1 + " from probablitystate1", cn.con);
 dt = new DataTable();
 da.Fill(dt);
 dataGridView1.DataSource = dt;
 
Share this answer
 
v2
Comments
usha C 15-Jul-13 2:26am    
Thank you ...Thnks lot
Remove single quotes in your query.

C#
da = new SqlDataAdapter("select " + a + "," + a1 + " from probablitystate1 ", cn.con);
 
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