把SELECT * FROM PRODUCE 中查出的所有数据的DUCE字段的数据都累加,并放入TEXTBOX中,不如何做呢?高手帮忙啊

解决方案 »

  1.   

    CREATE TABLE [dbo].[cmproduce] (
    [produceID] [int] IDENTITY (1, 1) NOT NULL ,
    [Class] [char] (40) COLLATE Chinese_PRC_CI_AS NULL ,
    [subUnit] [char] (20) COLLATE Chinese_PRC_CI_AS NULL ,
    [YearPlan] [float] NULL ,
    [MonthPlan] [float] NULL ,
    [DayPlan] [float] NULL ,
    [Complete] [float] NULL ,
    [MonthTotal] [float] NULL ,
    [Spare] [float] NULL ,
    [YearTotal] [float] NULL ,
    [ProduceDate] [datetime] NULL ,
    [Unit] [char] (40) COLLATE Chinese_PRC_CI_AS NULL 
    ) ON [PRIMARY]
    GO这是我的表结构,要求能统计MonthTotal,Complete等的累计
      

  2.   

    select 
    [produceID], [Class], [subUnit] , sum([YearPlan]) as YearPlan, sum([MonthPlan] ), sum( [DayPlan] ), sum([Complete] ), sum([MonthTotal] ),
    sum( [Spare]),sum( [YearTotal]),
    from
    cmproduce
    group by produceID,Class,subUnit其他的sum的写法类似sum([YearPlan]) as YearPlan,就可以了.
      

  3.   

    public static string sumyear(string month) {
            SqlConnection con = DBoperate.createDB();
            con.Open();
            SqlCommand cmd = new SqlCommand("select SUM(monthToTAL) from cmproduce where month(produceDate)='" + month + "' and year(ProduceDate)='" + month + "' ", con);
            string  summonth = Convert.ToString(cmd.ExecuteScalar());
            return summonth.ToString();
     
        }
    这样写怎么string  summonth = Convert.ToString(cmd.ExecuteScalar());老是报错啊,怎么改呢?
      

  4.   

    SqlConnection con = DBoperate.createDB();
            SqlCommand cmd = new SqlCommand("select SUM(monthToTAL) from cmproduce where month(produceDate)='" + month + "' and year(ProduceDate)='" + month + "' ", con);
    con.Open();//把conn.open()放到下面一行就可以了