none
未找到列 [Convert(LateTime,'System.Double')]是什么意思? RRS feed

  • 问题

  • 我从数据库读取数据到datatable中,然后进行统计:table.Compute("Sum([Convert(LateTime,'System.Double')])", "Numbers='2012'"),原来的LateTime字段是字符型,我现在要统计这一列中的所有不为空的数值,现在报错“未找到列 [Convert(LateTime,'System.Double')]”是怎么回事呢,请教各位高手指点一下。

    2013年7月2日 14:11

答案

  • DataTable dt = new DataTable();
                dt.Columns.Add("Id"typeof(string));
                dt.Columns.Add("Name"typeof(string));
                dt.Rows.Add("11.00");
                dt.Rows.Add("2.00");
                dt.Rows.Add("11.00");
                var value = (dt.AsEnumerable().Where(row => row["Id"]!=DBNull.Value && Convert.ToDouble(row["Id"]) > 2.0)).Sum(row => Convert.ToDouble(row["Id"]));
                Console.WriteLine(value);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年7月3日 5:44
    版主

全部回复

  • table.Compute("Sum(Convert(LateTime,'System.Double'))", "Numbers='2012'")
    2013年7月2日 14:47
  • table.Compute("Sum(Convert(LateTime,'System.Double'))", "Numbers='2012'")

    感谢朋友的回复,你这个是错的,会弹出:聚合参数中的语法错误: 需要具有可能的“Child”限定符的单个列参数。
    2013年7月3日 0:36
  •  DataTable dt = new DataTable();
                dt.Columns.Add("Id"typeof(string));
                dt.Columns.Add("Name"typeof(string));
                dt.Rows.Add("11.00");
                dt.Rows.Add("2.00");
                dt.Rows.Add("11.00");
                var value = (dt.AsEnumerable().Where(row => Convert.ToDouble(row["Id"]) > 2.0)).Sum(row => Convert.ToDouble(row["Id"]));
                Console.WriteLine(value);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年7月3日 1:53
    版主
  •  DataTable dt = new DataTable();
                dt.Columns.Add("Id"typeof(string));
                dt.Columns.Add("Name"typeof(string));
                dt.Rows.Add("11.00");
                dt.Rows.Add("2.00");
                dt.Rows.Add("11.00");
                var value = (dt.AsEnumerable().Where(row => Convert.ToDouble(row["Id"]) > 2.0)).Sum(row => Convert.ToDouble(row["Id"]));
                Console.WriteLine(value);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report


    感谢朋友的回复,我对LINQ和Lambda表达式不是很熟,如果列值有可能有空值的情况下怎么办呢?
    2013年7月3日 5:34
  • DataTable dt = new DataTable();
                dt.Columns.Add("Id"typeof(string));
                dt.Columns.Add("Name"typeof(string));
                dt.Rows.Add("11.00");
                dt.Rows.Add("2.00");
                dt.Rows.Add("11.00");
                var value = (dt.AsEnumerable().Where(row => row["Id"]!=DBNull.Value && Convert.ToDouble(row["Id"]) > 2.0)).Sum(row => Convert.ToDouble(row["Id"]));
                Console.WriteLine(value);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年7月3日 5:44
    版主
  • DataTable dt = new DataTable();
                dt.Columns.Add("Id", typeof(string));
                dt.Columns.Add("Name", typeof(string));
                dt.Rows.Add("11.00");
                dt.Rows.Add("2.00");
                dt.Rows.Add("11.00");
                var value = (dt.AsEnumerable().Where(row => row["Id"]!=DBNull.Value && Convert.ToDouble(row["Id"]) > 2.0)).Sum(row => Convert.ToDouble(row["Id"]));
                Console.WriteLine(value);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report


    谢谢朋友,你的方法非常好,我成功决定了三个条件下的筛选统计。
    2013年7月3日 6:18