DataRelation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: DataRelation

  1. #1
    Join Date
    Feb 2006
    Posts
    6

    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

  2. #2
    Join Date
    Feb 2006
    Posts
    6
    ok my problem solve. I have found my error..

    How can I make my item in link_title as a navigation url link?
    Last edited by lovelyhelp; 02-17-2006 at 09:24 AM.

Similar Threads

  1. Access database connectivity
    By Tomas in forum ASP.NET
    Replies: 2
    Last Post: 04-05-2002, 02:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center