var names = new string[] { "编号", "名称", "数值" }; var columns = new string[] { "ID", "NAME", "NUM" }; this.comboBox1.DataSource = names; this.comboBox1.Tag = columns;var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
还是没有用对,每次选择后,只是提交过去ID,如果选择名称,也是ID,不是NAME。
那您帮我看一下这段代码 是哪里有问题? var list = new List<Tuple>(3); var names = new string[] { "物料代码", "物料名称", "规格型号", "单价", "属性" }; var column = new string[] { "matID", "matName", "model", "price", "attr" }; this.comboBox1.DataSource = list; this.comboBox1.DataSource = names; this.comboBox1.Tag = column; var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex]; dataGridView1.DataSource = MyClass.getDataSet("select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where " + result + " like '%" + textBox1.Text.Trim() + "%'");
不管怎么选择,一直是"matID",而且只要点查询,还会报错。
// 绑定就这4行 var names = new string[] { "物料代码", "物料名称", "规格型号", "单价", "属性" }; var column = new string[] { "matID", "matName", "model", "price", "attr" }; this.comboBox1.DataSource = names; this.comboBox1.Tag = column;// 取值时才执行这行,result 就是结果 var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
嗯,我取值以后,在SQL语句中获取,连接到数据库,但是无论combobox怎么选 都是matID 是matID也就算了,但不知道为什么还报错。。sql语句也没有问题啊。。唉~~~。select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where matID like '%A%' var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex]; dataGridView1.DataSource = MyClass.getDataSet("select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where " + result + " like '%" + textBox1.Text.Trim() + "%'");
public class Tuple
{
public string name { get; set; }
public string column { get; set; }
}// 绑定代码
var list = new List<Tuple>(3);
list.Add(new Tuple { name = "编号", column = "ID" });
list.Add(new Tuple { name = "名称", column = "NAME" });
list.Add(new Tuple { name = "数值", column = "NUM" });
this.comboBox1.DataSource = list;
this.comboBox1.DisplayMember = "name";
this.comboBox1.ValueMember = "column";// 取值
var result = this.comboBox1.SelectedValue;
var columns = new string[] { "ID", "NAME", "NUM" };
this.comboBox1.DataSource = names;
this.comboBox1.Tag = columns;var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
var names = new string[] { "物料代码", "物料名称", "规格型号", "单价", "属性" };
var column = new string[] { "matID", "matName", "model", "price", "attr" };
this.comboBox1.DataSource = list;
this.comboBox1.DataSource = names;
this.comboBox1.Tag = column; var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
dataGridView1.DataSource = MyClass.getDataSet("select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where " + result + " like '%" + textBox1.Text.Trim() + "%'");
var names = new string[] { "物料代码", "物料名称", "规格型号", "单价", "属性" };
var column = new string[] { "matID", "matName", "model", "price", "attr" };
this.comboBox1.DataSource = names;
this.comboBox1.Tag = column;// 取值时才执行这行,result 就是结果
var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
是matID也就算了,但不知道为什么还报错。。sql语句也没有问题啊。。唉~~~。select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where matID like '%A%'
var result = ((string[])this.comboBox1.Tag)[this.comboBox1.SelectedIndex];
dataGridView1.DataSource = MyClass.getDataSet("select matID as '物料代码',matName as '物料名称',model as '规格型号',price as '单价',onhandQty as '库存',unit as '单位',Explanation as '产品说明',attr as '属性' FROM material where " + result + " like '%" + textBox1.Text.Trim() + "%'");