| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 915 人关注过本帖
标题:为何在ASP.NET中将数组赋值给Excel工作表的单元格上不成功?
只看楼主 加入收藏
foshan
Rank: 1
等 级:新手上路
威 望:2
帖 子:605
专家分:0
注 册:2006-3-1
结帖率:100%
收藏
 问题点数:0 回复次数:0 
为何在ASP.NET中将数组赋值给Excel工作表的单元格上不成功?
以下代码试图用泛型取得数据库的数据后再转成数组,然后将数组赋值给Excel工作表的单元格,但不成功。请教大家应如何解决,谢谢!
public void ExcelMethod(string service)
        {
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString);

            SqlCommand cmd = new SqlCommand(
                    @"SELECT Id, Weight, Name, City, State, WebsiteUrl, Latitude, Longitude
              FROM Athlete
              WHERE (Weight = @Weight)", cn);

            cmd.Parameters.AddWithValue("Weight", service);

            List<AnAthlete> retrievedAthletes = new List<AnAthlete>();

            cn.Open();
            using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                while (dr.Read())
                {
                    retrievedAthletes.Add(new AnAthlete(dr.GetInt32(0),
                                                        dr.GetString(1),
                                                        dr.GetString(2),
                                                        dr.GetString(3),
                                                        dr.GetString(4),
                                                        dr.GetString(5),
                                                        dr.GetDouble(6),
                                                        dr.GetDouble(7)));
                }
            }
            rng = ws.get_Range("B5", "H10");
            rng.Value2 = retrievedAthletes.ToArray();
        }
搜索更多相关主题的帖子: 赋值 Excel NET 中将 ASP 
2008-01-29 15:38
快速回复:为何在ASP.NET中将数组赋值给Excel工作表的单元格上不成功?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021463 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved