Dim ds As New DataSet() Dim dt As New DataTable("MyTable") Dim dr As DataRow dt.Columns.Add(New System.Data.DataColumn("Column1", GetType(Integer))) dt.Columns.Add(New System.Data.DataColumn("Column2", GetType(Integer))) dr = dt.NewRow() dr(0) = 1 dr(1) = 2 'continue adding rows here 'add the Row values to Table dt.Rows.Add(dr) 'add the Table to DataSet ds.Tables.Add(dt)
2015年5月3日 星期日
Here's an example on how to add Table to DataSet:
2015年4月30日 星期四
vb.net 手動增加DataTable
- Jun 15 Tue 2010 19:45
VB.NET- 手動建立DataTable
無論是數據的整理或是由伺服器撈下來的資料
總需要填入DataTable 中作彙整並方便程式操作
總需要填入DataTable 中作彙整並方便程式操作
當然
如果是由資料庫撈下來的資料
只要丟進表格中就大功告成
但若是要手動輸入資料而資料量不大
並不需要進資料庫時呢?
如果是由資料庫撈下來的資料
只要丟進表格中就大功告成
但若是要手動輸入資料而資料量不大
並不需要進資料庫時呢?
那就手工做一個吧!!
以下介紹如何『純手工打造黃金DataTable 』(哈!!)
以下介紹如何『純手工打造黃金DataTable 』(哈!!)
'(1) 建立空白資料表格DataTable
'請先引用 System.Data 命名空間
'因為 DataTable 是被定義在該命名空間中
DataTable dt = new DataTable();'建立資料表--定義dt為一資料表 並實體化
'(2) 建立欄位資訊
dt.Columns.Add("編號");
dt.Columns.Add("姓名");
dt.Columns.Add(" 電話");
'(3)塞資料
'請先引用 System.Data 命名空間
'因為 DataTable 是被定義在該命名空間中
DataTable dt = new DataTable();'建立資料表--定義dt為一資料表 並實體化
'(2) 建立欄位資訊
dt.Columns.Add("編號");
dt.Columns.Add("姓名");
dt.Columns.Add(" 電話");
'(3)塞資料
'由於Row的建立,必須取出DataTable的欄位資訊'所以不可以使用new來建立空白的 Row
'必須透過DataTable的NewRow()方法來取得一筆有欄位資訊的Row
'取出新的Row後,填入適當的資料
'再透過 DataTable中的Rows集合裡的Add()方法將Row附加到DataTable中。
DataRow row = dt.NewRow();
row["編號"]=1;
row["姓名"]="小豬";
row["電話"]=" (07)727-5246";
dt.Rows.Add(row);
'(4)資料呈現
'在網頁中拉一個Gridview控制項(Form則改用DataGridView)
Gridview.DataSource = dt '使用Gridview呈現表格
'必須透過DataTable的NewRow()方法來取得一筆有欄位資訊的Row
'取出新的Row後,填入適當的資料
'再透過 DataTable中的Rows集合裡的Add()方法將Row附加到DataTable中。
DataRow row = dt.NewRow();
row["編號"]=1;
row["姓名"]="小豬";
row["電話"]=" (07)727-5246";
dt.Rows.Add(row);
'(4)資料呈現
'在網頁中拉一個Gridview控制項(Form則改用DataGridView)
Gridview.DataSource = dt '使用Gridview呈現表格
資料來源:古埃及法老的金字塔
2015年4月29日 星期三
取得月份有幾天
C#
int 這個月的天數 = DateTime.DaysInMonth(年,月);
VB
Dim 這個月的天數 As Integer = DateTime.DaysInMonth(年,月)
int 這個月的天數 = DateTime.DaysInMonth(年,月);
VB
Dim 這個月的天數 As Integer = DateTime.DaysInMonth(年,月)
訂閱:
文章 (Atom)