By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

many-ro-many relationship in VS2005 C#

P: 2
I have books, authors and a bkauthlink table linking the other two tables-a many-to-many relationship. I have tried various things but cannot create a Data Relation. Is there no way to do this in VS2005 or is there a website that discusses it (I have Googled for days). See errors commented by code line.

I have this in Program.cs class:
Expand|Select|Wrap|Line Numbers
  1. namespace BooksAuthors
  2.  
  3. {
  4. static class Program
  5. {
  6. // The main entry point for the application.
  7. [STAThread]
  8.  
  9. static void Main()
  10. {
  11. Application.EnableVisualStyles();
  12. Application.SetCompatibleTextRenderingDefault(false);
  13. Application.Run(new MainForm());
  14. }
  15. }
  16. }
  17.  
and get error on Application.Run(new MainForm());
"Child list for field Authors cannot be created"

Here's the class for the data:

Expand|Select|Wrap|Line Numbers
  1. namespace BooksAuthors
  2. {
  3. internal class ClassDataHandling
  4. {
  5. public void MainDataClass()
  6. {
  7. string connString = @"Server=RHOADESD;Integrated Security=True;" +
  8. "Database=BOOKS";
  9.  
  10. SqlConnection conn = new SqlConnection(connString);
  11. SqlDataAdapter booksAdapter = new SqlDataAdapter(
  12. "Select * from books", conn);
  13.  
  14. SqlDataAdapter bkauthlinkAdapter = new SqlDataAdapter(
  15. "Select * from bkauthlink", conn);
  16.  
  17. SqlDataAdapter authorAdapter = new SqlDataAdapter(
  18. "Select * from authors", conn);
  19.  
  20. conn.Open();
  21.  
  22.  
  23. DataSet BookAuthDataSet = new DataSet("BookAuthors");
  24. booksAdapter.Fill(BookAuthDataSet, "books");
  25. bkauthlinkAdapter.Fill(BookAuthDataSet, "bkauthlink");
  26. authorAdapter.Fill(BookAuthDataSet, "authors");
  27.  
  28. conn.Close();
  29.  
  30. DataRelation book = BookAuthDataSet.Relations.Add(
  31. "BookRel", BookAuthDataSet.Tables["books"].Columns["booksID"],
  32. BookAuthDataSet.Tables["bkauthlink"].Columns["booksID"]);
  33.  
  34. DataRelation author = BookAuthDataSet.Relations.Add(
  35. "AuthRel", BookAuthDataSet.Tables["authors"].Columns["authorsID"],
  36. BookAuthDataSet.Tables["bkauthlink"].Columns["authorsID"]);
  37.  
Mar 2 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.