my_lou Posted May 12, 2004 Posted May 12, 2004 is there a way to get a DataView to contain data from multiple DataTables in a DataSet? The MSDN .NET framework says: "Represents a databindable, customized view of a DataTable....", i.e. just one DataTable per DataView. I was thinking of using DataViewManager, but it simply contains a collection of DataViews for the DataTables in the DataSet, i.e. you can't represent more than one table in a data view. Thanks. Quote
*Experts* Nerseus Posted May 12, 2004 *Experts* Posted May 12, 2004 No, a DataView cannot show data from more than one DataTable. I can think of two alternatives offhand: 1. Use expression columns in a DataTable that reference values from another table. 2. Use a custom class, like JoinView from Microsoft. For #1 to work, you have to have a relationship in your DataSet. The expression can use Parent and Child to reference the other table, depending on your relationship. The expression doesn't come without drawbacks. For one, they don't update automatically in all circumstances. For another, you can't use something like GetChanges if one of the tables that changed was in the relationship while the other isn't. Option 2 means using custom, potentially buggy, code. Also, if you want it in C#, you have to convert. I converted it to C# and it's been working fine for me but I don't use it to modify any data in the DataSet, only get a joined-view of data. Before you ask, No, I can't release the converted project - I've asked my boss and he said nope. It only took 3 or 4 hours and that included adding a custom constructor for my purposes (to automatically add all columns from one DataTable or the other). -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
my_lou Posted May 13, 2004 Author Posted May 13, 2004 hey thanks Nerseus. The JoinView class looks exactly like what i was looking for and better yet, it's in VB.NET like my app so no conversion needed. Let me see now if i can get this thing to work. No, a DataView cannot show data from more than one DataTable. I can think of two alternatives offhand: 1. Use expression columns in a DataTable that reference values from another table. 2. Use a custom class, like JoinView from Microsoft. For #1 to work, you have to have a relationship in your DataSet. The expression can use Parent and Child to reference the other table, depending on your relationship. The expression doesn't come without drawbacks. For one, they don't update automatically in all circumstances. For another, you can't use something like GetChanges if one of the tables that changed was in the relationship while the other isn't. Option 2 means using custom, potentially buggy, code. Also, if you want it in C#, you have to convert. I converted it to C# and it's been working fine for me but I don't use it to modify any data in the DataSet, only get a joined-view of data. Before you ask, No, I can't release the converted project - I've asked my boss and he said nope. It only took 3 or 4 hours and that included adding a custom constructor for my purposes (to automatically add all columns from one DataTable or the other). -Nerseus Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.