c# html datatable,C# DataTable使用方法详解
//創(chuàng)建一個(gè)名為"dt"的空表
DataTable dt = new DataTable("dt");
//1.創(chuàng)建空列
DataColumn dc =new?DataColumn();
dt.Columns.Add(dc);
//2.創(chuàng)建帶列名和類型名的列(兩種方式任選其一)
dt.Columns.Add("column0", System.Type.GetType("System.String"));
dt.Columns.Add("column0",typeof(String));
//3.通過(guò)列架構(gòu)添加列
DataColumn dc =new?DataColumn("column1",System.Type.GetType("System.DateTime"));
DataColumn dc =new?DataColumn("column1",typeof(DateTime));
dt.Columns.Add(dc);
//1.創(chuàng)建空行
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
//2.創(chuàng)建空行
dt.Rows.Add();
//3.通過(guò)行框架創(chuàng)建并賦值
dt.Rows.Add("張三",DateTime.Now);//Add里面參數(shù)的數(shù)據(jù)順序要和dt中的列的順序?qū)?yīng)
//4.通過(guò)復(fù)制dt2表的某一行來(lái)創(chuàng)建
dt.Rows.Add(dt2.Rows[i].ItemArray);
//對(duì)表已有行進(jìn)行賦值
dt.Rows[0][0] ="張三";//通過(guò)索引賦值
dt.Rows[0]["column1"] = DateTime.Now;//通過(guò)名稱賦值
//取值
string?name=dt.Rows[0][0].ToString();
string?name=dt.Rows[0][列名稱].ToString();
篩選列為null
DataRow[] drs = dt.Select("column1 is null");
//使用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();
/復(fù)制表,同時(shí)復(fù)制了表結(jié)構(gòu)和表中的數(shù)據(jù)
DataTable dtNew =new?DataTable();
dtNew = dt.Copy();
//復(fù)制表
DataTable dtNew = dt.Copy();//復(fù)制dt表數(shù)據(jù)結(jié)構(gòu)
dtNew.Clear()//清空數(shù)據(jù)
//克隆表,只是復(fù)制了表結(jié)構(gòu),不包括數(shù)據(jù)
DataTable dtNew =new?DataTable();
dtNew = dt.Clone();
dtNew.ImportRow(dt.Rows[0]);//這是加入的是第一行
DataView dv = dt.DefaultView;//獲取表視圖
dv.Sort ="ID DESC";//按照ID倒序排序
dv.ToTable();//轉(zhuǎn)為表
標(biāo)簽:Rows,C#,Add,詳解,dtNew,new,dt,DataTable
來(lái)源: https://blog.csdn.net/qq_36248777/article/details/98945760
總結(jié)
以上是生活随笔為你收集整理的c# html datatable,C# DataTable使用方法详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: vivo计算机隐藏游戏,vivo
- 下一篇: 计算机基础知识统考12月份,(精)201