n Overloads Public Overridable Function Add() As DataTable
n Overloads Public Overridable Sub Add(ByVal table As DataTable)
n Overloads Public Overridable Function Add(ByVal name As String) As DataTable
n Public Sub AddRange(ByVal tables() As DataTable)
参数
1. table 要添加的 DataTable 对象。
2. name 要赋予已创建的 DataTable 的名称。
3. tables 要添加到集合中的 DataTable 对象的数组。
DataTableCollection 包含特定 DataSet 的所有 DataTable 对象。若要访问 DataSet 的 DataTableCollection,请使用 Tables 属性。
DataTableCollection 使用诸如 Add、Clear 和 Remove 之类的方法管理集合中的项目。
使用 Contains 方法确定集合中是否有特定表(由索引或名称指定)。
若要从一个表浏览到另一个表,请使用 DataTable 的 ChildRelations 或 ParentRelations 属性来访问它的 DataRelation 对象的集合。还可使用 Relations 属性浏览给定的 DataSet 集合中 DataTables 的父/子关系。
示例
Private Sub AddTable()
Dim dSet As DataSet= CType(DataGrid1.DataSource, DataSet)
Dim dt As DataTable
dt = dSet.Tables.Add("myNewTable")
MessageBox.Show(dt.TableName)
MessageBox.Show(dSet.Tables.Count.ToString() & " tables")
Dim i As Integer
For i = 0 to 2
dSet.Tables.Add()
Next i
MessageBox.Show(dSet.Tables.Count.ToString() & " tables")
Dim tables As DataTableCollection = CType(DataGrid1.DataSource, DataSet).Tables
tables.Add(New DataTable)
MessageBox.Show(dSet.Tables.Count.ToString() & " tables")
Dim t As DataTable
Dim r As DataRow
Dim c As DataColumn
For Each t In dSet.Tables
Console.WriteLine(t.TableName)
For Each r In t.Rows
For Each c in t.Columns
If Not (r(c) Is Nothing) Then
Console.WriteLine(r(c))
End If
Next
Next
Next
Dim t1 As DataTable = New DataTable("Customers" )
t1.Columns.Add("customerId", Type.GetType("System.Int32")).AutoIncrement = True
t1.Columns.Add("name", Type.GetType("System.String"))
t1.PrimaryKey = New DataColumn() { t1.Columns("customerId") }
Dim t2 As DataTable = New DataTable("Orders" )
t2.Columns.Add("orderId", Type.GetType("System.Int32")).AutoIncrement = True
t2.Columns.Add("customerId", Type.GetType("System.Int32"))
t2.Columns.Add("amount", Type.GetType("System.Double"))
t2.PrimaryKey = New DataColumn() { t2.Columns("orderId") }
dSet.Tables.AddRange( New DataTable() {t1, t2} )
For Each t In dSet.Tables
Console.WriteLine(t.TableName )
For Each c In t.Columns
Console.Write("{0}" & vbTab, c.ColumnName)
Next
Console.WriteLine()
Next
MessageBox.Show(dSet.Tables.Count.ToString() & " tables")
End Sub
[C语言系列][C#]数组和datatable间的相互转换 [C语言系列]C# DataTable转换byte互转 [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体
|