组合框中的选定值不读取 [英] Selected Values in a combobox is not reading
本文介绍了组合框中的选定值不读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cmd = new SqlCommand("select intrfacname from transfer where ipad='" + comboBox2.SelectedItem.ToString() + "'", cn.con);
dr1 = cmd.ExecuteReader();
while (dr1.Read())
{
textBox2.Text = dr1[0].ToString();
}
dr1.Dispose();
cmd.Dispose();
Am选择组合框值并读入文本框但该选定索引的值未读取字符串在dis代码之前我绑定组合框中的值,其代码在这里,但它的工作原理
Am Selecting the combo box value and read into an text box but value of that selected index is not reading in a string Before dis code i bind the values in combo box the code for that is here but it works
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select ipad from transfer where ntwrk='" + comboBox1.SelectedItem.ToString() + "'", cn.con);
dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ipad", typeof(string));
// dt.Columns.Add("contactname", typeof(string));
dt.Load(dr);
comboBox2.ValueMember = "ipad";
comboBox2.DisplayMember = "ipad";
comboBox2.DataSource = dt;
cmd.Dispose();
dr.Dispose();
}
但上面的读取代码的代码不起作用帮我解释
But the above code for reading a value does not work help me pls
推荐答案
只是更新它... ....
Just Update itlike that....:)
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select ipad from transfer where ntwrk='" + comboBox1.SelectedItem.ToString() + "'", cn.con);
dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ipad", typeof(string));
// dt.Columns.Add("contactname", typeof(string));
dt.Load(dr);
comboBox2.DataSource = dt;
comboBox2.ValueMember = "ipad";
comboBox2.DisplayMember = "ipad";
cmd.Dispose();
dr.Dispose();
}
你可以试试这个:
comboBox1.SelectedValue。 ToString();
Hi,
you can try this:
comboBox1.SelectedValue.ToString();
试试这个...... :)
Try this....:)
cmd = new SqlCommand("select intrfacname from transfer where ipad='" + comboBox2.SelectedItem.ToString() + "'", cn.con);
dr1 = cmd.ExecuteReader();
while (dr1.Read())
{
textBox2.Text = dr1[0]["intrfacname"].ToString();
}
dr1.Dispose();
cmd.Dispose();
这篇关于组合框中的选定值不读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文