DataTable-Add实现

发布时间:2022-06-29 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了DataTable-Add实现脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

第一步:声明

1             DataTable recordsToShow = new DataTable();
2             recordsToShow.Columns.Add("ResultID", typeof(string));
3             recordsToShow.Columns.Add("Username", typeof(string));
4             recordsToShow.Columns.Add("RealName", typeof(string));
5             recordsToShow.Columns.Add("CompanyName", typeof(string));
6             recordsToShow.Columns.Add("BTime", typeof(string));
7             recordsToShow.Columns.Add("ETime", typeof(string));
8             recordsToShow.Columns.Add("Score", typeof(string));
9             recordsToShow.Columns.Add("IP", typeof(string));

第二步:给DataTable 赋值   

examResults用于循环赋值的数组
 1                 foreach (var result in examResults)
 2                 {
 3                     var row = recordsToShow.NewRow();
 4                     row.SetField("Username", result.Username);
 5                     row.SetField("ResultID", result.Result_ID);
 6                     row.SetField("RealName", NetTrmp.Common.BLL.People.GetPeopleNameByUsername(result.Username));
 7                     row.SetField("CompanyName", NetTrmp.Common.BLL.People.GetCompanyNameByUsername(result.Username, true));
 8                     row.SetField("BTime", result.BTime.HasValue ? result.BTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty);
 9                     row.SetField("ETime", result.ETime.HasValue ? result.ETime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty);
10                     row.SetField("Score", (result.Score * result.Rate).Value.ToString(numberformatstring));
11                     row.SetField("IP", result.IP);21 
22                     recordsToShow.Rows.Add(row);
23                 }

 

脚本宝典总结

以上是脚本宝典为你收集整理的DataTable-Add实现全部内容,希望文章能够帮你解决DataTable-Add实现所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: