c#如何使用datatable实例
1、1.创建表
DataTable dt=new DataTable("User");
添加列
dt.Columns.Add("user_name",typeof(string));
dt.Columns.Add("user_password",typeof(string));
dt.Columns.Add("user_page",typeof(int));

2、赋值操作,添加操作
若要向 DataTable 中添加行,必须先使用 NewRow 方法返回新的 DataRow 对象。NewRow 方法返回具有 DataTable 的架构的行,就像由该表的 DataColumnCollection 定义的那样。DataTable 可存储的最大行数是 16,777,216。

3、DataRow dr=dt.NewRow();
dr[0]="zs";
dr[1]="zhangsan";
dr[2]=20;
dt.Rows.Add(dr);

4、 DataTable 也包含可用于确保数据完整性的 Constraint 对象的集合
当访问 DataTable 对象时,请注意它们是按条件区分大小写的。
一个 DataSet 可以包含两个 DataTable 对象,它们具有相同的 TableName 属性值和不同的 Namespace 属性值。

5、删除操作
使用DataTable.Rows.Remove(DataRow)方法dt.Rows.Remove(dt.Rows[0]);
使用DataTable.Rows.RemoveAt(index)方法dt.Rows.RemoveAt(0);
使用DataRow.Delete()方法dt.Row[0].Delete(); dt.AcceptChanges();

6、//查找行 DataRow[] drs = dt.Select("id is null"); Response.Write(drs.Length.ToString()+"<br/>"); DataRow[] drs1 = dt.Select("id is not null"); Response.Write(drs1.Length.ToString() + "<br/>");
