国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

合并兩個DataSet的數據內容的方法

2020-01-18 00:07:16
字體:
來源:轉載
供稿:網友

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();
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富宁县| 新邵县| 龙里县| 兴义市| 隆安县| 那曲县| 亳州市| 车险| 仁布县| 麻城市| 文昌市| 来宾市| 小金县| 余庆县| 彭州市| 潮安县| 师宗县| 青海省| 青州市| 苏州市| 大英县| 托克托县| 宁波市| 天水市| 中方县| 阿瓦提县| 北流市| 东兴市| 聊城市| 灵山县| 定安县| 吉安县| 东海县| 玛纳斯县| 白沙| 安阳县| 乐昌市| 曲麻莱县| 十堰市| 盐源县| 城口县|