|
隨便寫寫, this is VB, 可能有typo, 用LINQ更快, 不過你是初學者就這樣做.
要先Imports進來datatable的命名空間System.Data
Dim dt1 as new datatable
Dim dv1 as dataview
Dim dc as datacolumn
Dim dt2 as new datatable
Dim dr as datarow
Dim i as integer
'..... create 你要的data column
dc = new datacolumn()
dc.Name = "StockCode"
dc.DataType = Type.[GetType]("System.String")
dt1.columns.add(dc)
'.....
'..... create whatever columns 你要的
'把你要的資料新增到dt1
dr = dt1.newrow
dr("StockCode") = ???
dr("FieldName2") = ???
dt.rows.add(dr)
'我喜歡用dataview, 用datatable直接排序也行
dv1 = new dataview(dt1)
dv1.Sort = "Volumn DESC"
' create 你要的 dt2, 或是直接複製dt1的結構
for i = 0 to 5
dr = dt2.NewRow
dr("FieldName1") = dv1(i)("FieldName1")
dr("FieldName2") = dv1(i)("FieldName2")
.......
'把資料列複製到dt2
dt2.rows.add(dr)
Next
'甘巴爹
|
|