在传递数据集表以便转换为列表时返回异常。
//here i am passing dataset tables to FromDataRow
var list = ClassA.FromDataRow(ds.Tables[1].AsEnumerable());
//here is function implementation
public class ClassA
{
public List<UserDesignation> UserDesigGrid { get; set; }
public static ClassA FromDataRow(IEnumerable<DataRow> userDesignationDetails, IEnumerable<DataRow> userContactDeails, IEnumerable<DataRow> userCategoryDetails)
{
var classA = new ClassA
{
UserDesigGrid = userDesignationDetails.Select(r => new UserDesignation
{
USER_ID = (int)r["USER_ID"],
DESIGNATION = (string)r["DESIGNATION"],
USER_TYPE = (string)r["LOCATION_TYPE"],
LOCATION = (string)r["LOCATION_ID_NAME"],
EFFECTIVE_FROM = (string)r["WEF_DATE"],
EFFECTIVE_TO = (string)r["WET_DATE"],
}).ToList()
};
return classA;
}
}
//property layer
public class UserDesignation
{
public int USER_ID { get; set; }
public string DESIGNATION { get; set; }
public string USER_TYPE { get; set; }
public string LOCATION { get; set; }
public string EFFECTIVE_FROM { get; set; }
public string EFFECTIVE_TO { get; set; }
}
转换时返回异常
“无法将类型为'System.Decimal'的对象强制转换为类型 'System.String'“
答案 0 :(得分:1)
没有从decimal到string的隐式或显式转换。你可以尝试:
string yourString = a.ToString();
其中a是十进制变量。