Vb.net数据库连接失败了

时间:2012-08-15 09:57:05

标签: asp.net vb.net dataset

我有以下代码,我正在尝试使用这些信息更新新的数据库行。我很确定我之前已经这样做了,但它在线上有'NullReferenceExcetption'

dtItemsFeed = taItemsFeed.GetData()

代码(修剪)如下:

Public Partial Class downloaditems

    Private dtItemsFeed As dsItems.ItemsFeedDataTable
    Private taItemsFeed As dsItemsTableAdapters.ItemsFeedTableAdapter

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        checkSite("http://www.tiag.me/whatever/header.html", "Header")

    End Sub

    Private Sub checkSite(ByVal URL As String, ByVal Type As String)

        dtItemsFeed = taItemsFeed.GetData()
        Dim rFeed As dsItems.ItemsFeedRow

        rFeed = dtItemsFeed.NewItemsFeedRow

      ### Code that loads items ###

        rFeed.HeaderCode = sourcecode
        rFeed.LastImport = System.DateTime.Now
        rFeed.Verified = "True"

        dtItemsFeed.AddItemsFeedRow(rFeed)
        taItemsFeed.Update(dtItemsFeed)

    End Sub

End Class

当我查看编辑数据集时数据有效,所以我知道它正在连接

错误:enter image description here

任何帮助都将非常感激。汤姆

2 个答案:

答案 0 :(得分:0)

您必须创建dsItemsTableAdapters.ItemsFeedTableAdapter的对象。

Private taItemsFeed As new dsItemsTableAdapters.ItemsFeedTableAdapter

答案 1 :(得分:0)

您没有为taItemsFeed分配值的代码。因此,当您达到该代码时,它始终为Nothing

你或你错过了一些基本代码!