Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

"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
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...