ADO.NET对象的构造(4)_DataColumn(续)
2024-07-10 12:59:38
供稿:网友
n 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