linq问题求助
//soure 为datatale 日期为第二列 形式:2013-2-29 有空值var columns = source.Rows.Cast<DataRow>().Select(x =>
{
DateTime dt = default(DateTime);
try
{
dt = Convert.ToDateTime(x[2]);
}
catch { }
return dt;
}).Distinct().OrderBy(x => x);
foreach (DateTime item in columns)
dt1.Columns.Add(item.ToShortDateString().ToString())
var data = from x in source.Rows.Cast<DataRow>()
group x by x[1] into g
select new { Key = g.Key.ToString(), Items = g }
string[] array = new string[dt1.Columns.Count];
//从第二列开始 for循环
array[i] = (from y in x.Items
where y[2].ToString().Substring(0,9) == dt1.Columns[i].ToString()
select int.Parse(y[3].ToString())).Sum().ToString();
如以上三段代码,x[2]为第二列是日期,但有空值,取值的时候可以把空值变为自己设的默认值,但是分组排序后,空值要参加计算,怎么办??请大家指点一下
linq --------------------编程问答-------------------- 程序大概要实现的是,以第一列来分组,得到一个新的表,把日期那列转换为行,第三类为产品数量,计算相同日期的产品数量 --------------------编程问答-------------------- 现在的关键问题是,把日期提变为新表的列时,空值已经转为默认值了,但把原表以第1列分组时,日期空值一直没变,如何把原表日期为空的,也变为默认值就没问题了
补充:.NET技术 , C#