combobox绑定了数据源,想在combob内容改变的同时改变textbox中的内容,代码每次都提示取不到数据
部分代码:privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){DBConnect();s...
部分代码:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DBConnect();
sqlcon.Open();
string i = comboBox1.SelectedItem.ToString();
SqlCommand scd = new SqlCommand("select ID as 学号,StudentName as 姓名,Sex as 性别 from Student where ID='"+i+"'", sqlcon);
SqlDataReader sdr = scd.ExecuteReader();
sdr.Read();
textBox1.Text = sdr["姓名"].ToString();
textBox2.Text = sdr["性别"].ToString();
}
都不行啊,真郁闷 展开
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DBConnect();
sqlcon.Open();
string i = comboBox1.SelectedItem.ToString();
SqlCommand scd = new SqlCommand("select ID as 学号,StudentName as 姓名,Sex as 性别 from Student where ID='"+i+"'", sqlcon);
SqlDataReader sdr = scd.ExecuteReader();
sdr.Read();
textBox1.Text = sdr["姓名"].ToString();
textBox2.Text = sdr["性别"].ToString();
}
都不行啊,真郁闷 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询