Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

DataRelation

i trying to create parent hyperlink and children hyperlink. I have my parent table name t_linkchapter and children t_linktitle..where link_chapterid is the primary key in table t_linkchapter and i also set link_chapterid as foreign key in t_linkchapter

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
[3644 byte] By [lovelyhelp] at [2007-11-11 8:02:15]
# 1 Re: DataRelation
ok my problem solve. I have found my error..

How can I make my item in link_title as a navigation url link?
lovelyhelp at 2007-11-11 23:13:26 >