Solved

dataset relations (vb.net)

Posted on 2003-11-12
11
2,415 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 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