大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> ADO.NET对象的构造(4)_DataColumn

ADO.NET对象的构造(4)_DataColumn

时间: 2021-07-31 作者:daque

datacolumn结构n public sub new()’ 刚创造时,新的 datacolumn 东西没有默许的 columnname 或 caption 属性。然而,在增添到 datacolumncollection 时,就赋予列默许称呼(“column1”、“column2”之类)。n public sub new(byval columnname as string)n public sub new(byval columnname as string,byval datatype as type)n public sub new(byval columnname as string,byval datatype as type,byval expr as string)n public sub new(byval columnname as string,byval datatype as type,byval expr as string,byval type as mappingtype)参数1. columnname 一个字符串,它表白要创造的列的称呼。即使树立为空援用(visual basic 中为 nothing)或空字符串 (""),则当增添到列汇合中时,将供给一个默许称呼。 2. datatype 扶助的 datatype。 3. expr 用来创造该列的表白式。4. type mappingtype 值之一。指定怎样映照 datacolumn。在获得或树立 datacolumn 的 columnmapping 属性时,运用 mappingtype 列举。在 dataset 上挪用 writexml 本领以将数据和框架结构动作 xml 文书档案写出时,该属性决定怎样写列的值。分子称呼 证明attribute 将列映照到 xml 属性。element 将列映照到 xml 元素。hidden 将列映照到里面构造。simplecontent 将列映照到 xmltext 节点。datacolumn 是用来创造 datatable 的框架结构的基础结构块。经过向 datacolumncollection 中增添一个或多个 datacolumn 东西来天生这个框架结构。每个 datacolumn 都有 datatype 属性,该属性决定 datacolumn 所包括的数据的品种。比方,不妨将数据典型控制为平头、字符串或少量。因为 datatable 所包括的数据常常兼并回其原始数据源,所以必需使数据典型与数据源中的数据典型配合。诸如 allowdbnull、unique 和 readonly 之类的属性对数据的输出和革新强加控制,进而无助于于保证数据完备性。还不妨运用 autoincrement、autoincrementseed 和 autoincrementstep 属性来遏制数据机动天生。还不妨经过创造 uniqueconstraint 并将其增添到 datacolumn 分属的 datatable 的 constraintcollection,以保证 datacolumn 中的值是独一的。若要创造 datacolumn 东西之间的联系,请创造 datarelation 东西并将其增添到 dataset 的 datarelationcollection。不妨运用 datacolumn 东西的 expression 属性来计划列中的值或创造会合列。示例private sub createcomputedcolumn(byval mytable as datatable) dim mytable as datatable = new datatable("mytable") dim mycolumn as datacolumn dim dt as system.typedim strexpr as stringmycolumn = new datacolumn("id") with mycolumn .datatype = system.type.gettype("system.int32") .autoincrement = true .autoincrementseed = 1 .autoincrementstep = 1 .readonly = true end withmytable.columns.add(mycolumn) dt = system.type.gettype("system.int32")mycolumn = new datacolumn("quantity", dt) with mycolumn .allowdbnull = false end with mytable.columns.add(mycolumn) mycolumn = new datacolumn mycolumn.datatype = system.type.gettype("system.decimal") mycolumn.allowdbnull = false mycolumn.caption = "price" mycolumn.columnname = "price" mycolumn.defaultvalue = 25 mytable.columns.add(mycolumn) dt = system.type.gettype("system.decimal") mycolumn = new datacolumn("tax", dt, "price * .0862") with mycolumn .autoincrement = false .readonly = true end withmytable.columns.add(mycolumn) dt = system.type.gettype("system.decimal") strexpr = "price * quantity" ' create the column, setting the type to attribute. mycolumn = new datacolumn("total", dt, strexpr, mappingtype.attribute) mycolumn.autoincrement = false mycolumn.readonly = true mytable.columns.add(mycolumn) end sub

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.