Methods for merging data content from two datasets _ Practical Tips

Source: Internet
Author: User

Default.aspx

Copy Code code 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 ">

<title> Untitled Page </title>
<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"/>
<editrowstyle backcolor= "#2461BF"/>
<alternatingrowstyle backcolor= "White"/>
</asp:GridView>
</div>
</form>
</body>

Default.aspx.cs

Copy Code code 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 (); To create a source data set
DataSet Dstarget = new DataSet (); To create a destination dataset
String constr = configurationmanager.connectionstrings["Constr"]. ToString ();
using (SqlConnection con = new SqlConnection (CONSTR))//Create data connection
{
To create a data adapter
SqlDataAdapter SDA = new SqlDataAdapter ("select * from Dictionarytype", con);
Sda. Fill (Dssource, "Dictionarytype");//Add dictionary class to source dataset

SDA = new SqlDataAdapter ("select * from Dictionaryitem", con);
Sda. Fill (Dstarget, "Dictionaryitem");//Add dictionary values to the destination dataset
}
Dstarget.merge (Dssource); Merge the Dictionarytype table of the source dataset into the target dataset
Gridview1.datasource = dstarget.tables["Dictionarytype"];
Gridview1.databind ();
}
}

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.