Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
textbox value changed according to combobox value changed from sql.

Sql vales are :

mid    descr	       PSupervisor
      1	   Abhijeet           Anant Gaikar
      2	   Abhimanyu     	Anant 


i have used below code but not working ,

in textbox its show me a full query.


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtPsupervisor.Text = "select psupervisor from Master.OringOperator where descr ='" + comboBox1.SelectedValue.ToString() + "'";

}


pls chnges in code

thnks in advance.
Posted
Updated 7-Aug-13 0:21am
v2
Comments
[no name] 7-Aug-13 6:29am    
"but not working", on the contrary. The code is working and doing exactly what you told it to do. If you actually want to get data from a database, you need to connect to whatever database you are using, execute the query and then do whatever it is you want to do with the data.
Master Vinu 7-Aug-13 6:36am    
i hv create the coonection on top of the page ...plese chnged in code to know ...yhx in advance sir

1 solution

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (objConn1.State != ConnectionState.Open)
{
objConn1.Open();
}

SqlCommand cm = new SqlCommand ( "select psupervisor from Master.OringOperator where descr ='" + comboBox1.SelectedValue.ToString() + "'",objConn1);

SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
txtPsupervisor.Text = Convert.ToString(dr["psupervisor"]); ;
}
objConn1.Close();

}
 
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