DataRelation
my code are as below. but i found and compilation error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 39:
Line 40: 'call the relationship of two table
Line 41: relation = New DataRelation("linkChapterTitle", ds.Tables("link_title").Columns("link_chapterid"), ds.Tables("link_chapter").Columns("link_chapterid"))
Line 42:
Line 43: ds.Relations.Add(relation)
how to solve my problem?
------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conTutorial As SqlConnection
Dim cmdSelect As SqlCommand
Dim cmdSelect2 As SqlCommand
Dim SqlDataAdapter1 As SqlDataAdapter
Dim SqlDataAdapter2 As SqlDataAdapter
Dim ds As New DataSet()
'Dim column1 As DataColumn
'Dim column2 As DataColumn
Dim relation As DataRelation
Dim Chapter As DataRow
Dim Title As DataRow
Dim arrRows() As DataRow
conTutorial = New SqlConnection("Data Source=asc;Initial Catalog=userLogin;Persist Security Info=True;User ID=sa;Password=")
conTutorial.Open()
' call the link_chapter and link_title table
cmdSelect = New SqlCommand("select * from t_linkChapter", conTutorial)
SqlDataAdapter1 = New SqlDataAdapter(cmdSelect)
SqlDataAdapter1.Fill(ds, "t_linkChapter")
' column1 = ds.Tables("link_chapter").Columns("link_chapterid")
cmdSelect2 = New SqlCommand("select * from t_linkTitle", conTutorial)
SqlDataAdapter2 = New SqlDataAdapter(cmdSelect2)
SqlDataAdapter2.Fill(ds, "t_linkTitle")
'column2 = ds.Tables("link_title").Columns("link_chapterid")
'call the relationship of two table
relation = New DataRelation("linkChapterTitle", ds.Tables("link_title").Columns("link_chapterid"), ds.Tables("link_chapter").Columns("link_chapterid"))
ds.Relations.Add(relation)
For Each Chapter In ds.Tables("Chapter").Rows
arrRows = Chapter.GetChildRows(ds.Relations("linkChapterTitle"))
If arrRows.Length > 0 Then
hyperlink.Text += "<u><b>" + Chapter("link_chapter") + "</b></u><br>"
hyperlink.Text += "<ul>"
For Each Title In arrRows
hyperlink.Text += "<li>" + Title("link_title") + "</li><br>"
Next
hyperlink.Text += "</ul>"
End If
Next
'call the table t_torial from database
'cmdSelect3 = New SqlCommand("SELCET [tut_text],[tut_image],[tut_sound] FROM t_tutorial", conTutorial)
conTutorial.Close()
End Sub

