Overloads Public Overridable Function Add() As DataColumn
n Overloads Public Sub Add(ByVal column As DataColumn)
n Overloads Public Overridable Function Add(ByVal columnName As String) As DataColumn
n Overloads Public Overridable Function Add(ByVal columnName As String, ByVal type As Type) As DataColumn
n Overloads Public Overridable Function Add(ByVal columnName As String, ByVal type As Type,ByVal expression As String) As DataColumn
参数
1. columnName 列的名称。
2. column 要添加的 DataColumn。
3. type 新列的 DataType。
4. expression 要分配给 Expression 属性的表达式。
DataColumnCollection 定义 DataTable 的架构,并确定每个 DataColumn 可以包含什么种类的数据。可以通过 DataTable对象的 Columns 属性访问 DataColumnCollection。
DataColumnCollection 使用 Add 和 Remove 方法插入和删除 DataColumn 对象。使用 Count 属性确定集合中有多少 DataColumn 对象。使用 Contains 方法验证集合中是否存在指定索引或列名称。
示例
Private Sub AddColumn()
Dim cols As DataColumnCollection= DataSet1.Tables("Orders").Columns
Dim myCol As DataColumn
myCol = cols.Add()
With myCol
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "Total"
.Expression = "UnitPrice * Quantity"
.ReadOnly = True
.Unique = False
End With
myCol = New DataColumn
With myCol
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "Total"
.Expression = "UnitPrice * Quantity"
.ReadOnly = True
.Unique = False
End With
cols.Add(myCol)
myCol = cols.Add("Total", System.Type.GetType("System.Decimal"), "UnitPrice * Quantity")
myCol.ReadOnly = True
myCol.Unique = False
myCol = cols.Add("Total")
With myCol
.DataType = System.Type.GetType("System.Decimal")
.ReadOnly = True
.Expression = "UnitPrice * Quantity"
.Unique = False
End With
myCol = cols.Add("Total", System.Type.GetType("System.Decimal"))
myCol.Expression = "UnitPrice * Quantity"
myCol.ReadOnly = True
myCol.Unique = False
Dim col As DataColumn
For Each col in cols
Console.WriteLine(col.ColumnName)
Console.WriteLine(col.DataType.ToString)
Next
End Sub