|
-
February 27th, 2009, 11:56 AM
#1
DataRelation with many-to-many relationships
VS2005 C#
I have books, authors and a bkauthlink table linking the other two tables creating a many-to-many relationship. I have this in Program.cs class:
namespace BooksAuthors
{
static class Program
{
// The main entry point for the application.
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
and get error on Application.Run(new MainForm());
"Child list for field Authors cannot be created"
Here's the class for the data:
namespace BooksAuthors
{
internal class ClassDataHandling
{
public void MainDataClass()
{
string connString = @"Server=RHOADESD;Integrated Security=True;" +
"Database=BOOKS";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter booksAdapter = new SqlDataAdapter(
"Select * from books", conn);
SqlDataAdapter bkauthlinkAdapter = new SqlDataAdapter(
"Select * from bkauthlink", conn);
SqlDataAdapter authorAdapter = new SqlDataAdapter(
"Select * from authors", conn);
conn.Open();
DataSet BookAuthDataSet = new DataSet("BookAuthors");
booksAdapter.Fill(BookAuthDataSet, "books");
bkauthlinkAdapter.Fill(BookAuthDataSet, "bkauthlink");
authorAdapter.Fill(BookAuthDataSet, "authors");
conn.Close();
DataRelation book = BookAuthDataSet.Relations.Add(
"BookRel", BookAuthDataSet.Tables["books"].Columns["booksID"],
BookAuthDataSet.Tables["bkauthlink"].Columns["booksID"]);
DataRelation author = BookAuthDataSet.Relations.Add(
"AuthRel", BookAuthDataSet.Tables["authors"].Columns["authorsID"],
BookAuthDataSet.Tables["bkauthlink"].Columns["authorsID"]);
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|