Dim dt As New DataTable()
dt.Columns.Add("date")
dt.Columns.Add("num")
Dim row As DataRow = dt.NewRow()
row("date") = "2018/12/12"
row("num") = "1200"
dt.Rows.Add(row)
----或----
Dim dt As New DataTable()
dt.Columns.Add("date")
dt.Columns.Add("num")
dt.Rows.Add("2018/12/12","1200")
字串寫入陣列
Dim array_p As New ArrayList
For i As Integer = 0 To distTable.Rows.Count - 1
array_p.Add(distTable(i)("WO_NUMBER"))
Next
取DataTable裡某欄位不重覆資料
Dim dv As DataView = Lv_dt_D.DefaultView
Dim distTable As DataTable = dv.ToTable(True, "WO_NUMBER")
或
Dim Lv_dtGroup As DataTable = DTABLE.DefaultView.ToTable(True, "MCT_CUR_WO")
取DataTable的篩選條件
Dim find_rows As DataRow() = Lv_dt_D_b.Select("WO_NUMBER='" & array_p(j) & "'")
取DataTable某欄位的最大值
Dim v_max_seq As Integer = v_dt1.Compute("Max(SEQ)", "")
取DataTable進行條件加總
DTABLE.Compute("Sum(MCT_CUR_QTY)", "MCT_CUR_WO='" & Lv_dtGroup(i)("MCT_CUR_WO") & "'")
將欄位值轉數字型態
Dim v_dt1 As New DataTable
v_dt1.Columns.Add("SEQ")
v_dt1.Columns("SEQ").DataType = System.Type.GetType("System.Int32")
DataTable排序
dt.DefaultView.Sort = "AG DESC"
dt= dt.DefaultView.ToTable()
DataTable 欄位名稱變更
dt.Columns("DOCNO").ColumnName = "合約編號"
NameValueCollection 集合 [字典]
字串字典,只能使用字串,如果你操作的對象是字串,那這個類別絕對是你的首選,因為它可以省下轉型的動作。
NameValueCollection 特性如下:
1.一個索引鍵(Key)對應到多個內容(Value),不同於StringCollection。
2.用GetValues方法取得的值是陣列型態,所以在處理上要小心。
Dim nvc As NameValueCollection = New NameValueCollection()
nvc.Add("MES3002PJ_F1_A5_MAIN", "Form1")
nvc.Add("MES3002PJ_F2_B5_MAIN", "Form2")
nvc.Add("MES3002PJ_F3_A5_MAIN", "Form3")
nvc.Add("MES3002PJ_F4_B5_MAIN", "Form4")
Dim formName As String = Nothing
For i As Integer = 0 To nvc.Count - 1
If nvc.Keys(i) = name Then
formName = nvc(i)
End If
Next