C#編程實(shí)現(xiàn)DataTable添加行的方法
本文實(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;//步長(zhǎng)為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" });
希望本文所述對(duì)大家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)過(guò)濾、取前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#實(shí)現(xiàn)DataGridView控件行列互換的方法
這篇文章主要介紹了C#實(shí)現(xiàn)DataGridView控件行列互換的方法,涉及C#中DataGridView控件元素遍歷與添加操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08淺析C#?AsyncLocal如何在異步間進(jìn)行數(shù)據(jù)流轉(zhuǎn)
在異步編程中,處理異步操作之間的數(shù)據(jù)流轉(zhuǎn)是一個(gè)比較常用的操作,C#異步編程提供了一個(gè)強(qiáng)大的工具來(lái)解決這個(gè)問(wèn)題,那就是AsyncLocal,下面我們就來(lái)看看AsyncLocal的原理和用法吧2023-08-08C#語(yǔ)句先后順序?qū)Τ绦虻慕Y(jié)果有影響嗎
有朋友問(wèn)我,C#中C#語(yǔ)句先后順序影響程序的結(jié)果嗎?告訴大家,答案是肯定的,絕對(duì)影響程序的結(jié)果,所以在程序中一定要注意C#語(yǔ)句的順序2015-10-10C#獲取App.Config配置項(xiàng)的方法總結(jié)
在本篇內(nèi)容里小編給大家分享了C#獲取App.Config配置項(xiàng)的方法和相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。2019-03-03c#使用DotNetZip封裝類操作zip文件(創(chuàng)建/讀取/更新)實(shí)例
DotnetZip是一個(gè)開(kāi)源類庫(kù),支持.NET的任何語(yǔ)言,可很方便的創(chuàng)建,讀取,和更新zip文件。而且還可以使用在.NETCompact Framework中。2013-11-11C#制作多線程處理強(qiáng)化版網(wǎng)絡(luò)爬蟲(chóng)
這篇文章主要介紹了C#制作多線程處理強(qiáng)化版網(wǎng)絡(luò)爬蟲(chóng)的相關(guān)代碼,有想學(xué)習(xí)C#多線程編程的小伙伴可以參考下2016-09-09