Hi everyone
i have DataBase ( SQL Express ) that include some tables like:
Author Table { AuthorID , AuthorName , ... } (Primary Key = AuthorID)
Book Table { BookID , BookTitle , AuthorID , ... } (Foreign Key = AuthorID)
i use "LINQ to SQL Classes" so i can use the tables like objects ... so ... in the object "Book" there is an extra property called "Author" (Because Of that Foreign Key),
so i can use this code to get data to show on the forms :
Label1.Text=Book.Author.AuthorName;
i wanna add a DataGridView to the form and add "Book Table" as a DataSource to it with the columns { Book Title , Author }
but the AuthorName Column is empty , because i cant do :
dataGridView1.Columns[1].DataPropertyName="Author.AuthorName";
another way i tried was:
BooksDataContext BookDB=new BooksDataContext; var data=From d in BookDB.Book select d; foreach (var v in data) { dataGridView1.Rows.Add(v.BookTitle,v.Author.AuthorName);
}
it works, but what if some changes happen to the DataBase ???
i need to run the code above again but it will add all the books again, and .....
i tried doing the "Linda Liu's" Suggestion => http://blogs.msdn.com/b/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx
but i didn't understand it and it didn't work ....
Any Idea ???????