文本框值根据从sql更改的组合框值更改。在winform中 [英] textbox value changed according to combobox value changed from sql. in winform

查看:74
本文介绍了文本框值根据从sql更改的组合框值更改。在winform中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本框值根据从sql更改的组合框值更改。



Sql值为:



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提前。



pls chnges in code

thnks in advance.

推荐答案

private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)

{

if(objConn1.State!= ConnectionState.Open)

{

objConn1.Open();

}



SqlCommand cm = new SqlCommand(从Master.OringOperator中选择psupervisor,其中descr ='+ comboBox1.SelectedValue.ToString()+',objConn1);



SqlDataReader dr = cm.ExecuteReader();

if(dr.Read())

{

txtPsupervisor.Text = Convert.ToString(dr [psupervisor]); ;

}

objConn1.Close();



}
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();

}


这篇关于文本框值根据从sql更改的组合框值更改。在winform中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆