为何在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();
}