大家圣诞节好!这段代码提示"未将对象引用设置到对象的实例。 "请看看...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
'建立Dataset代码
dslocalking = New DataSet("localkings")
'建立DataTable对象
dslocalking.Tables.Add("dtproduct")
'建立字段对象-productid(产品编号)
Dim clproductId As New DataColumn("productId")
clproductId.MaxLength = 10
'将字段对象productiD加入datatabel对象中,并指定她的数据类型
dtproduct.Columns.Add("productId", GetType(System.String))
'建立字段对象-productname(产品名称)
Dim clproductname As New DataColumn("productname")
clproductname.MaxLength = 30
'将字段对象productiD加入datatabel对象中,并指定她的数据类型
dtproduct.Columns.Add("productname", GetType(System.String))
clproductname.AllowDBNull = False
'建立product的键值
Dim pkproduct As Constraint = dtproduct.Constraints.Add("pk_productid", dtproduct.Columns("productid"), True)
'产品名称不能重复
dtproduct.Constraints.Add(New UniqueConstraint("uc_productname", dtproduct.Columns("productname")))
If Not IsPostBack Then
'如果product.xml不存在
If Dir("c:\product.xml") = "" Then
dslocalking.WriteXml("c:\product.xml")
End If
End If
gdproduct.DataSource = dslocalking.Tables("product")
dslocalking.ReadXml("c:\product.xml")
gdproduct.DataBind()
End Sub
运行后提示"未将对象引用设置到对象的实例"
行 40: clproductId.MaxLength = 10
行 41: '将字段对象productiD加入datatabel对象中,并指定她的数据类型
行 42: dtproduct.Columns.Add("productId", GetType(System.String))
行 43: '建立字段对象-productname(产品名称)
行 44: Dim clproductname As New DataColumn("productname")
"