this.windConnection = new SqlConnection("Server=localhost; User=sa; PWD=111111;database=DFZQ;Asynchronous Processing=true");
            this.windConnection.Open();
            this.windCommand = this.windConnection.CreateCommand();windCommand.CommandText = "SELECT  stockCode,sum(volume) FROM [DFZQ].[dbo].[fundPortfolio] where stopDate='" + tradingDate + "'group by stockCode";
            SqlDataReader sdr5 = windCommand.ExecuteReader();
            Dictionary<string, double> getSumStockVolume1 = new Dictionary<string, double>();
            foreach (KeyValuePair<string, double> pair in getSumStockVolume1)
            {
                string stockCode = (string)sdr5["stockCode"];
                double sumStockVolume1 = (double)sdr5["sum(volume)"];
                getSumStockVolume1.Add(stockCode, sumStockVolume1);
            }
            sdr5.Close();
            return getSumStockVolume1;

解决方案 »

  1.   

    ctionary<string, double> getSumStockVolume1 = new Dictionary<string, double>();
    foreach (KeyValuePair<string, double> pair in getSumStockVolume1)
    {}
    getSumStockVolume1中没有数据...
      

  2.   

    getSumStockVolume1 没有数据怎么会执行。你要先有返回的数据集才行
      

  3.   

    ctionary<string, double> getSumStockVolume1 = new Dictionary<string, double>();
    foreach (KeyValuePair<string, double> pair in getSumStockVolume1)
    {}
    getSumStockVolume1是你new出来的,没有数据,为空。
      

  4.   

    windCommand.CommandText = "SELECT stockCode,sum(volume) FROM [DFZQ].[dbo].[fundPortfolio] where stopDate='" + tradingDate + "'group by stockCode";
      SqlDataReader sdr5 = windCommand.ExecuteReader();
      Dictionary<string, double> getSumStockVolume1 = new Dictionary<string, double>();
      foreach (sdr5.Read())
      {
      string stockCode = (string)sdr5["stockCode"];
      double sumStockVolume1 = (double)sdr5["sum(volume)"];
      getSumStockVolume1.Add(stockCode, sumStockVolume1);
      }
      

  5.   

    失误!!!windCommand.CommandText = "SELECT stockCode,sum(volume) FROM [DFZQ].[dbo].[fundPortfolio] where stopDate='" + tradingDate + "'group by stockCode";
      SqlDataReader sdr5 = windCommand.ExecuteReader();
      Dictionary<string, double> getSumStockVolume1 = new Dictionary<string, double>();
      While(sdr5.Read())
      {
      string stockCode = (string)sdr5["stockCode"];
      double sumStockVolume1 = (double)sdr5["sum(volume)"];
      getSumStockVolume1.Add(stockCode, sumStockVolume1);
      } 这样就把它们放到字典dictionary里去了
      

  6.   

    漏了吧while(sdr5.Read())
    {
      String stockCode = String.Empty;
      if(!sdr5.IsDBNull(0))
      {
        stockCode = sdr5.GetString(0);
      }  Int32 sum = -1;
      if(!sdr5.IsDBNull(1))
      {
        stockCode = sdr5.GetInt(1);
      }  if(!String.IsNullOrEmpty(stockCode)
        && sum >0 )
      {
        getSumStockVolume1.Add(stockCode, sum);
      }
    }