C# DataTable转List
2021-02-05 17:15
标签:stat generic incr wro item list null reac rop ORM: 创建DataTable: 创建类 User C# DataTable转List 标签:stat generic incr wro item list null reac rop 原文地址:https://www.cnblogs.com/lujingBK/p/11438489.html 1 using System;
2 using System.Collections.Generic;
3 using System.Data;
4 using System.Linq;
5 using System.Reflection;
6 using System.Web;
7
8 namespace WebApplication1.date
9 {
10 public class ORM
11 {
12 static public List
1 DataTable tblDatas = new DataTable("User");
2 DataColumn dc = null;
3 dc = tblDatas.Columns.Add("Id", Type.GetType("System.Int32"));
4 dc.AutoIncrement = true;//自动增加
5 dc.AutoIncrementSeed = 1;//起始为1
6 dc.AutoIncrementStep = 1;//步长为1
7 dc.AllowDBNull = false;//
8
9 dc = tblDatas.Columns.Add("Name", Type.GetType("System.String"));
10 dc = tblDatas.Columns.Add("Pwd", Type.GetType("System.String"));
11
12 DataRow newRow;
13 newRow = tblDatas.NewRow();
14 newRow["Name"] = "张三";
15 newRow["Pwd"] = "123";
16 tblDatas.Rows.Add(newRow);
17
18 newRow = tblDatas.NewRow();
19 newRow["Name"] = "李四";
20 newRow["Pwd"] = "123456";
21 tblDatas.Rows.Add(newRow);
22 //调用ORM TOlist 泛型
23 var i = ORM.Tolist
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5
6 namespace ConsoleApp1
7 {
8 public class User
9 {
10 public int Id { get; set; }
11 public string Name { get; set; }
12 public string Pwd { get; set; }
13 }
14 }