值描述对编码 [英] Value description pair coding
问题描述
这是我在C#.net中用于值描述对的代码
This is my code for value description pair in C#.net
ddstyle.Items.Clear();
dr = con.reader("Select fg_mat_no,style_code+'('+fg_mat_no+')' from ces_style_master");
if (dr.HasRows)
{
ddstyle.Items.Add("==Select==");
while (dr.Read())
{
//ListItem objList = new ListItem(dr[0].ToString());
//combofgmat.Items.Add(New ValueDescriptionPair(connect.dr(0), connect.dr(1)))
ddstyle.Items.Add(new ValueDescriptionPair(dr[0].ToString(),dr[1].ToString()).ToString());
// ValueDescriptionPair(ddstyle.selecteditem).value;
//((ValueDescriptionPair)combofgmat.SelectedItem).Value
}
}
上面的代码说明了使用valuedescription类连接数据库中的两个值.
值说明编码如下所示:
The above code explain concatenating two values from database using valuedescription class.
The value description coding shown below:
public class ValueDescriptionPair
{
public string Value;
public string Description;
public ValueDescriptionPair(string NewValue, string NewDescription)
{
Value = NewValue;
Description = NewDescription;
}
public override string ToString()
{
return Description;
}
}
上面的作品很好
我在组合框中得到了串联的值,但是我在组合框中受到了限制,我将从下面的组合框中以c#的形式从组合框中获取值之一,但是它们给出了这样的错误:
无法将类型字符串"转换为"ValueDescriptionPair"
Above works very fine
I got the concatenated values in combo-box but i have restricted in the combo-box i will get one of the value from the combobox the below in written in c# but they give error like this:
Cannot convert type ''string'' to ''ValueDescriptionPair''
select op_need_name from ces_v_skill_operation_name where oper_need_code in (select distinct oper_need_code from ces_skill_style_master where fg_mat_no = ''" + ddstyle.SelectedItem.Value.ToString() + "'')and critical_code =''B''
请有人帮我
在此先感谢
pls somebody help me
Thanks in advance
推荐答案
这显然是类型转换的问题.
您的第二个问题还不太清楚.但是,无论哪里出现错误,只需尝试先使用其构造函数将字符串(产生错误)转换为ValueDescriptionPair,然后再使用它.
It''s clearly an issue of type conversion.
Your second half of question is not quite clear. But where ever you are getting that error, just try to convert the string(that is giving an error) into ValueDescriptionPair first using its constructor and then use it.
这篇关于值描述对编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!