Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help Regarding DATARELATIONSHIP

Help Regarding DATARELATIONSHIP

Scheduled Pinned Locked Moved C#
designhelptutorialquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amaankhan
    wrote on last edited by
    #1

    Please Friends Help me i have 4 tables 1. Master Book Table (MBookId,BookId,AuthorId,PubId) 2. Book Name ( BookId,BookName) 3. Author Name (AuthorId,AuthorName) 4. Publisher Name (PubId, PubName) DAL UI Layer DAL ---- Please suggest me how to achieve Datarelationship

    DataRelation dr = new DataRelation("BookBookName",
    ds.Tables["MBook"].Columns["BookId"],
    ds.Tables["Book"].Columns["BookId"]);

            ds.Relations.Add(dr);
    

    is this right ? and how to use this in UI to get data, insert,update, save.. etc i google a lot but didn't find the right solution for my purpose and is datarelation ship with dataset is better or NHIBERNATE if nhiberate is better then do ineed to start in from start i mean i have to create the tables and all that once.......... i have already created the datatable and DAL methods of Save Edit etc.... Please Help Thank you very much EveryOne..... (specially CODEPROJECT)

    L 1 Reply Last reply
    0
    • A amaankhan

      Please Friends Help me i have 4 tables 1. Master Book Table (MBookId,BookId,AuthorId,PubId) 2. Book Name ( BookId,BookName) 3. Author Name (AuthorId,AuthorName) 4. Publisher Name (PubId, PubName) DAL UI Layer DAL ---- Please suggest me how to achieve Datarelationship

      DataRelation dr = new DataRelation("BookBookName",
      ds.Tables["MBook"].Columns["BookId"],
      ds.Tables["Book"].Columns["BookId"]);

              ds.Relations.Add(dr);
      

      is this right ? and how to use this in UI to get data, insert,update, save.. etc i google a lot but didn't find the right solution for my purpose and is datarelation ship with dataset is better or NHIBERNATE if nhiberate is better then do ineed to start in from start i mean i have to create the tables and all that once.......... i have already created the datatable and DAL methods of Save Edit etc.... Please Help Thank you very much EveryOne..... (specially CODEPROJECT)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to do following.

      DataRelation dr = new DataRelation("BookBookName",
      ds.Tables["MBook"].Columns["BookId"],
      ds.Tables["Book"].Columns["BookId"]);

      DataRelation dr1 = new DataRelation("BookAuthorName",
      ds.Tables["MBook"].Columns["AuthorId"],
      ds.Tables["AName"].Columns["AuthorId"]);

      and so on. So you have finally four datarelation object. Then add all relation object to dataset, like..

      ds.Relations.Add(dr);
      ds.Relations.Add(dr1);
      ds.Relations.Add(dr2);

      You can do navigation as follows

      foreach (DataRow MBookRow in customerOrders.Tables["NBook"].Rows)
      {
      Console.WriteLine(MBookRow["MBookId"].ToString());

      foreach (DataRow BNameRow in MBookRow.GetChildRows(dr1))
      {
          Console.WriteLine(BNameRow\["BookId"\].ToString() + " " + BNameRow\["BookName"\].ToString());
      }
      

      }

      Refer this[^] link for DataSet Vs NHibernate. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups