-
DataTable 只保留想要的几列
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Collections.Generic;
-
- public partial class Default3 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- List<Person> list = new List<Person> {
- new Person(){Id=1,Name="小明'\"}[]{><,\\/~、\r\n"},
- new Person(){Id=2,Name="小华"}
- };
-
- DataTable dt = new DataTable("MatrixInfo");
- DataColumn dc1 = new DataColumn("ID");
- DataColumn dc2 = new DataColumn("Name");
- dt.Columns.Add(dc1);
- dt.Columns.Add(dc2);
- foreach (Person p in list)
- {
- DataRow dr = dt.NewRow();
- dr["ID"] = p.Id;
- dr["Name"] = p.Name;
- dt.Rows.Add(dr);
- }
-
- DataTable dv = dt.DefaultView.ToTable(false, new string[] { "Name" });
- }
-
- public class Person
- {
- public int Id { get; set; }
- public string Name { get; set; }
- }
- }
-
相关阅读:
C#中自动增量字段值的获取方法
Mio改造第一步
酒后
阳朔自驾行-行程篇
如何在C#中获取新插入的identity列值
格格生了
扯皮
nPdl的翻译
asp.net和asp的互相调用
NetBPM前进了一步,解决了上一个问题
-
原文地址:https://www.cnblogs.com/just09161018/p/4605483.html
Copyright © 2020-2023
润新知