大家圣诞节好!这段代码提示"未将对象引用设置到对象的实例。 "请看看...

lionosoft 2005-12-24 09:48:17
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")



"
...全文
391 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
水如烟 2005-12-24
  • 打赏
  • 举报
回复
If Dir("c:\product.xml") = "" Then
这样写法对吗?我没用过Dir
If Not IO.File.Exist("c:\product.xml") Then

如你这般写法,是不是
If Dir("c:\product.xml") Is Nothing Then

我不调试了,不好意思.
水如烟 2005-12-24
  • 打赏
  • 举报
回复
'建立字段对象-productid(产品编号)
Dim clproductId As New DataColumn("productId")
clproductId.MaxLength = 10
'将字段对象productiD加入datatabel对象中,并指定她的数据类型
dtproduct.Columns.Add("productId", GetType(System.String))
'''上面有点问题,但不是大问题
要不,
dtproduct.Columns.Add("productId", GetType(System.String))
要不,
Dim clproductId As New DataColumn("productId")
clproductId.MaxLength = 10
dtproduct.Columns.Add(clproductId)
yydwtbml 2005-12-24
  • 打赏
  • 举报
回复
出现这种提示通常都是未将对象实例化,即在新定义的变量前未使用new。

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧