我有一个模型:
public class KPIResults
{
public virtual string Title { get; set; }
public virtual int Total { get; set; }
public virtual int Week6 { get; set; }
public virtual int Week5 { get; set; }
public virtual int Week4 { get; set; }
public virtual int Week3 { get; set; }
public virtual int Week2 { get; set; }
public virtual int Week1 { get; set; }
public virtual string stringWeek6 { get; set; }
public virtual string stringWeek5 { get; set; }
public virtual string stringWeek4 { get; set; }
public virtual string stringWeek3 { get; set; }
public virtual string stringWeek2 { get; set; }
public virtual string stringWeek1 { get; set; }
}
在我的报告存储库中,我有:
int strfound = 0;
string str = "Number";
foreach (DataRow dr in dt.Rows)
{
string title = dr["Title"].ToString();
int total = Convert.ToInt32(dr["Total"]);
if (dr["Week6"].contains("Number") //synntacs not right?
var week6 = dr["strWeek6"]
end
or do this:
strfound = str.IndexOf(dr); //syntacs not right?
if (strfound == 0)
{
var week6 = dr["strWeek6"]
}
var week6 = Convert.ToInt32(dr["Week6"]);
var week5 = Convert.ToInt32(dr["Week5"]);
var week4 = Convert.ToInt32(dr["Week4"]);
var week3 = Convert.ToInt32(dr["Week3"]);
var week2 = Convert.ToInt32(dr["Week2"]);
var week1 = Convert.ToInt32(dr["Week1"]);
results.Add(new KPIResults() {Title = title, Total = total, Week6 = week6, Week5 = week5, Week4 = week4, Week3 = week3, Week2 = week2, Week1 = week1});
}
return results;
我也许应该尝试进行字符串搜索,但我在 is 中的代码不正确。我寻找处理字符串的方法,但不清楚。
谢谢