Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Accessing Relations


Message #1 by "Akshay Luther" <akshay@e...> on Tue, 30 Oct 2001 06:13:27 +1100
Hi,



Given any two tables in a database, I have to determine the common key

between them in order to perform a join.



I have tried using a SqlDataAdaptor to populate a DataSet and then iterate

through the relations, but 'Return' is always blank. All the material I've

seen on the web or in books only talks about establishing these

relationships and not reading them. Is this not possible with ADO.NET?



Will I have to use a COM wrapper for SQL-DMO to perform this instead?



Thanks in advance. Code follows.



      String Return = "";



      SqlDataAdapter da = new SqlDataAdapter

      (

        "select * from products" ,

        "server=FUDGE;database=Northwind;Trusted_Connection=yes"

      );



      DataSet ds = new DataSet();



      da.Fill(ds, "products");



      foreach (DataTable t in ds.Tables)

      {

        foreach (DataRelation r in t.ChildRelations)

        {

          Return += r.RelationName + "|";

        }

      }



Akshay Luther




  Return to Index