C#編程實(shí)現(xiàn)DataTable添加行的方法
更新時(shí)間:2015年11月16日 10:13:31 作者:Jan.David
這篇文章主要介紹了C#編程實(shí)現(xiàn)DataTable添加行的方法,結(jié)合兩個(gè)實(shí)例形式分析了C#操作DataTable實(shí)現(xiàn)動(dòng)態(tài)添加行的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#編程實(shí)現(xiàn)DataTable添加行的方法。分享給大家供大家參考,具體如下:
方法一:
DataTable tblDatas = new DataTable("Datas");
DataColumn dc = null;
dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//自動(dòng)增加
dc.AutoIncrementSeed = 1;//起始為1
dc.AutoIncrementStep = 1;//步長為1
dc.AllowDBNull = false;//
dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
DataRow newRow;
newRow = tblDatas.NewRow();
newRow["Product"] = "水果刀";
newRow["Version"] = "2.0";
newRow["Description"] = "打架專用";
tblDatas.Rows.Add(newRow);
newRow = tblDatas.NewRow();
newRow["Product"] = "折疊凳";
newRow["Version"] = "3.0";
newRow["Description"] = "行走江湖七武器之一";
tblDatas.Rows.Add(newRow);
方法二:
DataTable tblDatas = new DataTable("Datas");
tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
tblDatas.Columns[0].AutoIncrement = true;
tblDatas.Columns[0].AutoIncrementSeed = 1;
tblDatas.Columns[0].AutoIncrementStep = 1;
tblDatas.Columns.Add("Product", Type.GetType("System.String"));
tblDatas.Columns.Add("Version", Type.GetType("System.String"));
tblDatas.Columns.Add("Description", Type.GetType("System.String"));
tblDatas.Rows.Add(new object[]{null,"a","b","c"});
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
希望本文所述對大家C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- C# DataTable使用方法詳解
- C#實(shí)現(xiàn)DataTable映射成Model的方法(附源碼)
- C#保存與讀取DataTable信息到XML格式的方法
- C#實(shí)現(xiàn)將DataTable內(nèi)容輸出到Excel表格的方法
- C#從DataTable獲取數(shù)據(jù)的方法
- C#操作DataTable方法實(shí)現(xiàn)過濾、取前N條數(shù)據(jù)及獲取指定列數(shù)據(jù)列表的方法
- C#中DataTable實(shí)現(xiàn)行列轉(zhuǎn)換的方法
- C#將DataTable轉(zhuǎn)換成list的方法
- C#中datatable去重的方法
- C#中datatable序列化與反序列化實(shí)例分析
- C#中DataTable刪除行的方法分析
- C#實(shí)現(xiàn)從多列的DataTable里取需要的幾列
相關(guān)文章
C# DateTime與時(shí)間戳轉(zhuǎn)換實(shí)例
本篇文章主要介紹了C# DateTime與時(shí)間戳轉(zhuǎn)換實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
C#實(shí)現(xiàn)的三種模擬自動(dòng)登錄和提交POST信息的方法
這篇文章主要介紹了C#實(shí)現(xiàn)的三種模擬自動(dòng)登錄和提交POST信息的方法,分別列舉了WebBrowser、WebClient及HttpWebRequest實(shí)現(xiàn)自動(dòng)登錄及提交POST的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
WinForm實(shí)現(xiàn)鼠標(biāo)拖動(dòng)控件跟隨效果
這篇文章主要為大家詳細(xì)介紹了WinForm實(shí)現(xiàn)鼠標(biāo)拖動(dòng)控件跟隨效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03
c# richtextbox更新大量數(shù)據(jù)不卡死的實(shí)現(xiàn)方式
這篇文章主要介紹了c# richtextbox更新大量數(shù)據(jù)不卡死的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04
C#實(shí)現(xiàn)獲取Excel中圖片所在坐標(biāo)位置
本文以C#和vb.net代碼示例展示如何來獲取Excel工作表中圖片的坐標(biāo)位置,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-04-04
CAD2008+VS2008開發(fā)ObjectARX加載失敗問題(推薦)
這篇文章主要介紹了CAD2008+VS2008開發(fā)ObjectARX加載失敗問題,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04

