Default.aspx

复制代码 代码如下:

<%@ 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>无标题页</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

复制代码 代码如下:

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();        //创建源数据集
        DataSet dsTarget = new DataSet();        //创建目标数据集
        string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
        using (SqlConnection con = new SqlConnection(conStr))//创建数据连接
        {
            //创建数据适配器
            SqlDataAdapter sda = new SqlDataAdapter("select * from DictionaryType", con);
            sda.Fill(dsSource, "DictionaryType");//将字典类添加到源数据集

            sda = new SqlDataAdapter("select * from DictionaryItem", con);
            sda.Fill(dsTarget, "DictionaryItem");//将字典值添加到目标数据集
        }
        dsTarget.Merge(dsSource);   //将源数据集的DictionaryType表合并到目标数据集中
        GridView1.DataSource = dsTarget.Tables["DictionaryType"];
        GridView1.DataBind();
    }
}

标签:
合并,DataSet,数据

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“合并两个DataSet的数据内容的方法”

暂无“合并两个DataSet的数据内容的方法”评论...