tags:

views:

20

answers:

4
A: 

You want

comboBox2.SelectedValue

or

comboxBox2.SelectedItem.ToString()

then but I'd look at using parameters instead as that's not a very good way of creating a SQL string.

Also, do you realise that if you return more than one result your textbox2 will only show the last result as its text will get over-ridden with each result as its read?

w69rdy
NO actully the combox is binded with the database and the combox item selected is my primary key that will show the corresponding data in my textbox
thanxx bro it works when u put comboBox2.SelectedValue
+1  A: 

As well as that problem there are a few issues with your code that you might want to bear in mind.

Firstly, if there is an error between opening and closing the connection (as indeed there was) then you're probably going to leave connections open. Eventually this will choke your site. Use

using (SqlConnection cn = new SqlConnection())
{

}

when you're out of the scope of the using statement the connection will be closed and disposed of.

Also, you probably want to parameterize your query (for reasons both of security and efficiency), so that it is

sql = "SELECT inst_name FROM institude WHERE(inst_id=@inst_id)";

Then add that parameter to your command object and set its value to your combo box selected item value.

Yellowfog
A: 

First of all check the binding of dropdown. If you are binding datasource with ID and Text something like this combobox2.DisplayMember ="Name"; combobox2.ValueMember ="ID". After that you have to check for the parameter to be used in your query if its text then try combobox2.text else if you are selecting on the basis of id use int.parse(combobox2.selectedvalue) or simply combobox2.selectedvalue if your id is alphanumeric.

Amit Ranjan
A: