C#的如何或许combox.text的值
我现在做一个系统,可以读出了数据库里面的值,但是我一直等不出自己想要的结果,就是,我得到了combox里面的值,然后根据combox1.text里面的值来查找里一个数据表里面的值,一直得不出结果,大家帮一下忙,谢谢!代码如下:data dataconn = new data();
private string UserName;
public delbank(string a)
{
UserName = a;
string nm="";
InitializeComponent();
SqlDataReader dr = dataconn.read("select * from bankcar ");
while (dr.Read())
{
nm = dr["number"].ToString();
}
dr.Close();
SqlDataReader dr1 = dataconn.read("select * from bankcar where username='"+UserName+"'");
ArrayList tw = new ArrayList();
if (dr1.HasRows)
{
while (dr1.Read())
{
tw.Add(new DictionaryEntry(dr1["number"].ToString(), dr1["number"].ToString()));
}
this.comboBox1.DataSource = tw;
this.comboBox1.DisplayMember = "key";
this.comboBox1.ValueMember = "value";
}
dr1.Close();
this.comboBox1.SelectedValue = nm;
SqlDataReader dr2 = dataconn.read("select * from bank2 where number='" +comboBox1.Text+ "'");
while (dr2.Read())
{
this.textBox1.Text = dr2["balance"].ToString();
this.textBox2.Text = dr2["bank"].ToString();
}
dr2.Close(); --------------------编程问答-------------------- 调试啊,,看你的几个值是否是对的。。。
--------------------编程问答-------------------- SqlDataReader dr2 = dataconn.read("select * from bank2 where number='" +comboBox1.Text+ "'");
断点,看comboBox1.Text得值 --------------------编程问答-------------------- 我调试的时候,他会输出表的第一个值,好郁闷 --------------------编程问答-------------------- this.comboBox1.SelectedValue = nm;没有用的删除了看
--------------------编程问答-------------------- SqlDataReader dr2 = dataconn.read("select * from bank2 where number='" +comboBox1.Text+ "'");
while (dr2.Read())
{
this.textBox1.Text = dr2["balance"].ToString();
this.textBox2.Text = dr2["bank"].ToString();
}
dr2.Close();
这个写在selectChenged事件里 --------------------编程问答-------------------- 谢谢大侠。。。。。。哗啦啦
补充:.NET技术 , C#