C# Linq 将表按照IP进行排序

 1 /// <summary>
 2 /// 将表按照IP进行排序
 3 /// </summary>
 4 /// <param name="dt">数据表</param>
 5 /// <param name="columnName">字段</param>
 6 /// <returns></returns>
 7 public static DataTable LinqSortDataTable(DataTable dt, string columnName)
 8 {
 9     DataView dv = dt.DefaultView;
10     var query = (from item in dt.AsEnumerable()
11                  orderby (Convert.ToInt32(item[columnName].ToString().Split('.')[0])),
12                          (Convert.ToInt32(item[columnName].ToString().Split('.')[1])),
13                          (Convert.ToInt32(item[columnName].ToString().Split('.')[2])),
14                          (Convert.ToInt32(item[columnName].ToString().Split('.')[3]))
15                  select item);
16     dv = query.AsDataView();
17     return dv.ToTable();
18 }

 

posted @ 2022-09-05 17:05  Mr_Xul  阅读(34)  评论(0编辑  收藏  举报