|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IntroductionMerge is one of the method of Dataset. The merge feature is basically used in applications where the concept of Master and Transaction table exists. In this article we will see, how can we display two datasets in a single datagrid. For the merge to happen, we need to have the following pre-conditions. Pre-conditions for displaying two datasets in a single datagrid.
1) The primary thing is that, both all the columns specified in the datagrid
must be present in both datasets. A Merge walthrough.Assume that, we have two tables with the following structure.
You may be thinking that, how in the world we will have two table structures with the same structure and same field name. Yes, in batch processing, we will have two tables, master and transaction. Both these tables will have the same number of columns, same data type and same field name. Now, we need a datagrid to display records from the above tables. We assume that, we have a datagrid which contains the definition for all columns. If you wish, you can see the definiton of datagrid now itself. Click here to see the aspx page which uses a datagrid The data grid that we are talking about is the same as the datagrid which exist in the above sample (editdatagrid.html) We are mainly going to see the BindGrid method which binds the datasets with Datagrid. We will see, how can we bind two datasets with a single datagrid.
The above code will not work. Can you guess the reason? For the merge to take place, between datasets, apart from the data type and column name, the table should also be the same So, what should we do, inorder for merge to take place. We should name both the tables with same name. So, we have to modify the MyCommand.Fill method for both DS1 and DS2 as follows:
What, if the schema of two tables are not the same?
In this example, we saw that, the table structure of both tables (table1 and table2)
are the same. If the datatype of columns in table1 and table2 are not the same, then
what will happen. It is obvious that merge will not take place. Even the compiler
will give an error, such as: How can we create an editable Datagrid with two datasets?
Well, we very well can have a editable datagrid with two datasets sharing a same
datagrid. The only necessity for this is that, we should have some special values
in atleast one of the field in each table which depicts that this data belongs to table1.
To be more clear, in our first table, table1, the field3 can be used to store
information that belongs to its own table. For eg: for table1, the field3 can contain
a value called "master" which tells that, this data belongs to the table, master.
So, the records in the table1 will be as follows:
SummaryThus, we have gone through about how to Merge two datasets to a single datagrid. We can also merge between two datatable or even datarow. To know more about this, read the first link given in the links section.Linkshttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassMergeTopic2.asp http://aspalliance.com/das/editdatagrid.aspx Send your comments to das@aspalliance.com Back to Article list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 2000-2003 ASPAlliance.com Page Rendered at
11/7/2009 5:32:58 PM |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||