dataset--merge, merging data content from two datasets

Source: Internet
Author: User

In ASP., a dataset can contain more than one data table, and this instance is implemented by merging two data tables into a single dataset that contains all the tables in the original two datasets.

Key Technologies:the Merge method of a dataset allows you to merge the contents of another dataset, table collection, or row array into the current data set. The table's primary key, table name, constraints, and so on, all affect the effect of the merged dataset. The merge method is primarily used to merge the specified dataset and its schema into the current datasetpublic void Merge (DataSet DataSet);
code Example:
        protected voidPage_Load (Objectsender, EventArgs e) {DataSet Dssource=NewDataSet ();//Create a source datasetDataSet Dstarget =NewDataSet ();//Create a target dataset            stringConstr = configurationmanager.connectionstrings["Constr"].            ToString (); using(SqlConnection con =NewSqlConnection (CONSTR))//Create a data connection            {                //Creating a data adapterSqlDataAdapter SDA =NewSqlDataAdapter ("SELECT * from Dictionarytype", con); Sda. Fill (Dssource,"Dictionarytype");//to add a dictionary class to a source datasetSDA =NewSqlDataAdapter ("SELECT * from Dictionaryitem", con); Sda. Fill (Dstarget,"Dictionaryitem");//to add a dictionary value to a target dataset} dstarget.merge (Dssource); //to merge the Dictionarytype table of the source dataset into the target data setGridview1.datasource = dstarget.tables["Dictionarytype"];        Gridview1.databind (); }  

dataset--merge, merging data content from two datasets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.