Solved

dataset relations (vb.net)

Posted on 2003-11-12
11
2,412 Views
Last Modified: 2013-12-25
How can I import my database-relations in dataset-relations.
Now I typ them in as follows :
dim ds as new dataset
...
ds.relations.add("Order_detail", ds.tables("Order".colums("sernr"), ds.tables("Detail").colums("Order_sernr"))

But the same information already exists in my SQLserver !

Thanks.
0
Comment
Question by:dekeyzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 3

Accepted Solution

by:
SQLMaster earned 500 total points
ID: 9732511

To populate a DataSet with existing primary key constraint information from a data source, you have to call FillSchema method of the DataAdapter, or set the MissingSchemaAction property of the DataAdapter to AddWithKey before calling Fill. Please remember that foreign key constraint information is not included and will need to be created explicitly :-(

Thanks
0
 

Author Comment

by:dekeyzer
ID: 9738305
Ok, the primary key i have now but the relation not.
The Table object has the property's Parentrelation and childrelation but these are not filled in.
Any idee how i can populate them ?
0
 
LVL 3

Expert Comment

by:SQLMaster
ID: 9738476

parentRelations and childRelations are read only properties and they can only be read.

After you create relationships in DataSet, you can use these properties to get the required relations
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:dekeyzer
ID: 9738587
Can I find my database relations in vb so that i can create the dataset relations with that data.
I want to create the relationships in the dataset with my sql-datarelation information.
In VB6 i can get that information via ado.connection.openschema(adSchemaForeignKeys, Array(Empty, Empty, TableName)).
I don't know if that is possible in ado.net.
0
 
LVL 3

Expert Comment

by:SQLMaster
ID: 9739241
You can use DataTable.constraints property to see foreign and primary key relationships. This will return a constraintscollection that you can iterate to get the required info

Cheers
0
 

Author Comment

by:dekeyzer
ID: 9740180
Thanks, now i can make my primarykey constraints but the foreignkey constraints are missing.
Any idee how i can retrieve these form my SQLserver ?
0
 
LVL 3

Expert Comment

by:SQLMaster
ID: 9740699
Use SQLDataAdapter class for connecting to SQL Server. You should get your foreign key constraints in ConstraintsCollection
0
 

Author Comment

by:dekeyzer
ID: 9745759
I use the SQLdataadapter for connecting the SQLserver but no foreignkeyconstrains ar in the collection.
Here folows my code :

        Dim da as SqlDataAdapter
        Dim ds as DataSet
        Dim da2 As SqlDataAdapter
        Dim oTable As DataTable
        Dim oConstraint As Constraint
        Dim oColumn As DataColumn
        Dim oFK As ForeignKeyConstraint
        Dim oUK As UniqueConstraint

        sConn = "....."
        da = New SqlDataAdapter
        da2 = New SqlDataAdapter
        ds = New DataSet
        da.SelectCommand = New SqlCommand("Select * from kop")
        da.SelectCommand.Connection = New SqlConnection(sConn)
        da.MissingSchemaAction = MissingSchemaAction.AddWithKey
        da2.SelectCommand = New SqlCommand("Select * from det")
        da2.SelectCommand.Connection = New SqlConnection(sConn)
        da2.MissingSchemaAction = MissingSchemaAction.AddWithKey
        da.Fill(ds, "Order")
        da2.Fill(ds, "Detail")
        oTable = ds.Tables("Order")
        For Each oConstraint In oTable.Constraints
            MessageBox.Show(oConstraint.ConstraintName & " - " & oConstraint.ToString)
            If TypeOf oConstraint Is ForeignKeyConstraint Then
                oFK = CType(oConstraint, ForeignKeyConstraint)
                For Each oColumn In oFK.Columns
                    MessageBox.Show(oColumn.ColumnName())
                Next
            End If
            If TypeOf oConstraint Is UniqueConstraint Then
                oUK = CType(oConstraint, UniqueConstraint)
                For Each oColumn In oUK.Columns
                    MessageBox.Show(oColumn.ColumnName())
                Next
            End If
        Next

What do I wrong ?
0
 

Author Comment

by:dekeyzer
ID: 9745773
Sorry in the code above must the line
  da.SelectCommand = New SqlCommand("Select * from kop")
  da.SelectCommand = New SqlCommand("Select * from Order")
and
 da2.SelectCommand = New SqlCommand("Select * from det")
 da2.SelectCommand = New SqlCommand("Select * from Detail")
0
 
LVL 3

Expert Comment

by:SQLMaster
ID: 9746863
Sorry it is not possible to get foreign key constraints :-(
0
 

Author Comment

by:dekeyzer
ID: 9769618
I found an solution : the table sysforeignkeys has all the information that i need.

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 55
Add a task in Outlook from access 11 43
Visual Studio search word table and return Cell index 8 83
Added a column screws up code 5 75
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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