This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22785|Reply: 0

[Source] c# converts to a List collection method via DataTable

[Copy link]
Posted on 8/26/2015 1:04:38 PM | | |
  1. public static List<Dictionary<string, string>> GetTable(DataTable dt)
  2.         {
  3.             List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  4.             for (int i = 0; i < dt.Rows.Count; i++)
  5.             {
  6.                 Dictionary<string, string> dic = new Dictionary<string, string>();
  7.                 foreach (DataColumn dc in dt.Columns)
  8.                 {
  9.                     dic.Add(dc.ColumnName, dt.Rows[i][dc.ColumnName].ToString());
  10.                 }
  11.                 list.Add(dic);
  12.             }
  13.             return list;
  14.         }
Copy code
The teacher talked about the universal method, and finally converted it into JSON data.




Previous:The secret of Wuhan graduates looking for a job with a monthly income of 5,000 (including high-quality job recommendations)
Next:Campus projects urgently recruit partnership agents - waiting for you
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com