如何填充数据表

时间:2014-01-16 09:05:24

标签: c# sql-server

我试图在foreach循环中填充数据表,但它不起作用。我的代码是

 @helper PrintProductYearChart(IEnumerable<DynamicNode> products)
    {
        DataTable dt = new DataTable();
        foreach (var prd in products)
        {
            var query = "SELECT DISTINCT year(AddedDate) FROM Product WHERE PID='" + prd.Id + "' ORDER BY year(AddedDate) DESC";
            SqlDataReader reader = SqlHelper.ExecuteReader(umbraco.GlobalSettings.DbDSN, CommandType.Text, query);
            dt.Load(reader);
        }
    }

任何人都可以帮忙。谢谢

0 个答案:

没有答案