Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Accessing Relationships via ADO.NET


Message #1 by "Akshay Luther" <akshay@e...> on Mon, 29 Oct 2001 19:10:02
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 to 

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 + "|";

        }

      }

  Return to Index