Solved

VB.net Data Relation Creation

Posted on 2014-11-15
3
210 Views
Last Modified: 2014-11-15
I found the following example of creating a Data Relation. I get the error DataSet1 is not declared
What additional code do I need

http://msdn.microsoft.com/en-us/library/system.data.datarelation(v=vs.110).aspx

    Private Sub CreateRelation()
        ' Get the DataColumn objects from two DataTable objects  
        ' in a DataSet. Code to get the DataSet not shown here.
        Dim parentColumn As DataColumn = _
            DataSet1.Tables("Customers").Columns("CustID")
        Dim childColumn As DataColumn = DataSet1.Tables( _
            "Orders").Columns("CustID")

        ' Create DataRelation.
        Dim relCustOrder As DataRelation
        relCustOrder = New DataRelation( _
            "CustomersOrders", parentColumn, childColumn)

        ' Add the relation to the DataSet.
        DataSet1.Relations.Add(relCustOrder)
    End Sub
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40444441
Hi murbro;

From the error it sounds like you have not created a DataSet object. In other words you need to instantiate a DataSet object and in that object add to the Tables collection the two tables Customers and Orders. Then to that same DataSet object add to the Relations collection the relationship you created to it. In your code you call this DataSet object DataSet1.
0
 

Author Closing Comment

by:murbro
ID: 40444530
Thanks
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40444533
Not a problem murbro, glad to help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check ALL SP in database make sure there are no errors 17 43
SQL Activity Monitor detail 2 28
Syntax error with Dates where clause 10 47
xml files 7 24
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question