How to merge the data content of two datasets

Source: Internet
Author: User

Default. aspx

Copy codeThe Code is as follows:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: GridView ID = "GridView1" runat = "server" CellPadding = "4" ForeColor = "#333333"
GridLines = "None">
<RowStyle BackColor = "# EFF3FB"/>
<FooterStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>
<PagerStyle BackColor = "# 2461BF" ForeColor = "White" HorizontalAlign = "Center"/>
<SelectedRowStyle BackColor = "# D1DDF1" Font-Bold = "True" ForeColor = "#333333"/>
<HeaderStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>
<EditRowStyle BackColor = "# 2461BF"/>
<AlternatingRowStyle BackColor = "White"/>
</Asp: GridView>
</Div>
</Form>
</Body>
</Html>

Default. aspx. cs

Copy codeThe Code is as follows:

Using System;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Data. SqlClient;

Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
DataSet dsSource = new DataSet (); // create a source DataSet
DataSet dsTarget = new DataSet (); // create the target DataSet
String conStr = ConfigurationManager. ConnectionStrings ["conStr"]. ToString ();
Using (SqlConnection con = new SqlConnection (conStr) // create a data connection
{
// Create a data adapter
SqlDataAdapter sda = new SqlDataAdapter ("select * from DictionaryType", con );
Sda. Fill (dsSource, "DictionaryType"); // Add the dictionary class to the source Dataset

Sda = new SqlDataAdapter ("select * from DictionaryItem", con );
Sda. Fill (dsTarget, "DictionaryItem"); // Add the dictionary value to the target dataset.
}
DsTarget. Merge (dsSource); // combines the DictionaryType table of the source dataset into the target dataset.
GridView1.DataSource = dsTarget. Tables ["DictionaryType"];
GridView1.DataBind ();
}
}

Related Article

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.