注册 登录
编程论坛 ASP.NET技术论坛

诚心求教:datacolumn对象数据类型声明代码错误

lifongmaples 发布于 2010-12-13 20:32, 608 次点击
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)
dim pstab as new datatable()
dim pscol as new datacolumn

dim aa as string
aa="标题1"
pstab.tablename="mytab"
pscol=new datacolumn()
pscol.columnname=aa

**************'pscol.datatype=system.type.gettype("system.string")
此处为声明数据类型,程序运行到此就报错。请高人指点一二。诚谢!

pstab.columns.add(pscol)

response.write("<center><font size=13 color=blue>数据添加完成</font></center>")

end sub


</script>
2 回复
#2
冰镇柠檬汁儿2010-12-13 21:08
Private Sub MakeTable()
    ' Create a DataTable.
    Dim table As DataTable = new DataTable("Product")

    ' Create a DataColumn and set various properties.
    Dim column As DataColumn = New DataColumn
    column.DataType = System.Type.GetType("System.Decimal")
    column.AllowDBNull = False
    column.Caption = "Price"  
    column.ColumnName = "Price"
    column.DefaultValue = 25

    ' Add the column to the table.
    table.Columns.Add(column)

    ' Add 10 rows and set values.
    Dim row As DataRow
    Dim i As Integer  
    For i = 0 to 9
        row = table.NewRow()
        row("Price") = i + 1

        ' Be sure to add the new row to
        ' the DataRowCollection.
        table.Rows.Add(row)
    Next i
End Sub

这段代码希望对你有用,仔细看看,你应该能明白的,呵呵
#3
lifongmaples2010-12-13 22:31
回复 2楼 冰镇柠檬汁儿
谢谢!终于找到问题原因了。太伤脑筋了!
1