以下两种方法几乎完全相同。第一个工作正常,但第二个,LoadScreenIDs()
导致以下错误:
“System.NullReferenceException:对象引用未设置为 一个对象的实例。“
Public Function LoadFilmIDs()
Dim ScreeningsFilmIDTable = ChooseTable.ds.Tables("ScreeningsFilmID")
For Each dr As DataRow In ScreeningsFilmIDTable.Rows
cboFilm.Items.Add(dr.Item("FILMID").ToString())
Next
End Function
Public Function LoadScreenIDs()
Dim ScreeningsScreenIDTable = ChooseTable.ds.Tables("ScreeningsScreenID")
For Each dr1 As DataRow In ScreeningsScreenIDTable.Rows
cboScreen.Items.Add(dr1.Item("SCREENID").ToString())
Next
End Function
我看了一遍,并尝试了一切;改变方法,将所有方法都放在一个方法中,重命名对象和变量,但无济于事。
请帮忙。 :)
更新:以下是从数据库中实际请求数据的位置,实际表中肯定有数据。
Public Function LoadScreeningsScreenID() As DataSet
ds2 = New DataSet
Dim sql As String
Dim da As OracleDataAdapter
sql = "SELECT SCREENID from SYSTEM.SCREENS"
da = New OracleDataAdapter(sql, Connect())
da.Fill(ds2, "ScreeningsScreenID")
CloseDB()
Return ds2
End Function
Public Function LoadScreeningsFilmID() As DataSet
ds3 = New DataSet
Dim sql As String
Dim da As OracleDataAdapter
sql = "SELECT FILMID from SYSTEM.FILMS"
da = New OracleDataAdapter(sql, Connect())
da.Fill(ds3, "ScreeningsFilmID")
CloseDB()
Return ds3
End Function
解
Public Function PopulateAll() As DataSet
ds = New DataSet
Dim sql As String
Dim sql1 As String
Dim sql2 As String
Dim da As OracleDataAdapter
sql = "SELECT * from SYSTEM.SCREENINGS"
da = New OracleDataAdapter(sql, Connect())
da.Fill(ds, "Screenings")
sql1 = "SELECT FILMID from SYSTEM.FILMS"
da = New OracleDataAdapter(sql1, Connect())
da.Fill(ds, "ScreeningsFilmID")
sql2 = "SELECT SCREENID from SYSTEM.SCREENS"
da = New OracleDataAdapter(sql2, Connect())
da.Fill(ds, "ScreeningsScreenID")
lblStatus.Text = "Data loaded successfully"
CloseDB()
Return ds
End Function