列要求有效的 DataType
我在手工建立一个DataTable时出错了:___________________________________________________________
列要求有效的 DataType。
|
_______________________________________
<%@ Import Namespace="System.Data" %>
<%@ page debug="true" %>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)
dim dt as new datatable("link")
dim dc as datacolumn
dim dr as datarow
dc=new datacolumn()
dc.datatype=system.type.gettype("system.Int32")
dc.columnname="id"
dc.autoincrement=true
dc.autoincrementseed=1
dc.autoincrementstep=1
dt.columns.add(dc)
dc=new datacolumn()
dc.datatype=system.type.gettype("system.string")
dc.columnname="sitename"
dc.allowDBNull=false
dt.columns.add(dc)
dc=new datacolumn
dc.datatype=system.type.gettype("system.string")
dc.columnname="URL"
dc.allowDBNull=false
dt.columns.add(dc)
dim dckey() as datacolumn={dt.columns("id")}
dt.primarykey=dckey
dr=dt.newrow()
dr("sitename")="百度"
dr("URL")="http://baidu.com"
dt.rows.add(dr)
dr=dt.newrow
dr("sitename")="新浪"
dr("URL")="http://www.sina.com.cn"
dt.rows.add(dr)
dim ds as new dataset()
ds.tables.add(dt)
mydatagrid.datasource=ds.tables("link").defaultview
mydatagrid.datakeyfield="id"
mydatagrid.databind()
end sub