In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in turn, updating the original data are to:

  1. Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter.

  2. Change the data in individual DataTable objects by adding, updating, or deleting DataRow objects.

  3. Invoke the GetChanges method to create a second DataSet that features only the changes to the data.

  4. Call the Update method of the DataAdapter, passing the second DataSet as an argument.

  5. Invoke the Merge method to merge the changes from the second DataSet into the first.

  6. Invoke the AcceptChanges on the DataSet. Alternatively, invoke RejectChanges to cancel the changes.

DataRelation

ds.Tables.Add(table);
                    ds.Tables.Add(detailsTableSaved);

                    DataColumn[] pColumns = new DataColumn[] { table.Columns["DEPT_CODE"], table.Columns["CHECK_DATE"], table.Columns["INDEX_CODE"] };
                    DataColumn[] cColumns = new DataColumn[] { detailsTableSaved.Columns["DEPT_CODE"], detailsTableSaved.Columns["CHECK_DATE"], detailsTableSaved.Columns["INDEX_CODE"] };

                    DataRelation tDataRelation = new DataRelation("relation_Category_Product", pColumns, cColumns);
                    ds.Relations.Add(tDataRelation);

Master and Detail Relationship

// Add data from the Customers table to the DataSet.
            SqlDataAdapter masterDataAdapter = new
                SqlDataAdapter("select * from Customers", connection);
            masterDataAdapter.Fill(data, "Customers");

            // Add data from the Orders table to the DataSet.
            SqlDataAdapter detailsDataAdapter = new
                SqlDataAdapter("select * from Orders", connection);
            detailsDataAdapter.Fill(data, "Orders");

            // Establish a relationship between the two tables.
            DataRelation relation = new DataRelation("CustomersOrders",
                data.Tables["Customers"].Columns["CustomerID"],
                data.Tables["Orders"].Columns["CustomerID"]);
            data.Relations.Add(relation);

            // Bind the master data connector to the Customers table.
            masterBindingSource.DataSource = data;
            masterBindingSource.DataMember = "Customers";

            // Bind the details data connector to the master data connector,
            // using the DataRelation name to filter the information in the
            // details table based on the current row in the master table.
            detailsBindingSource.DataSource = masterBindingSource;
            detailsBindingSource.DataMember = "CustomersOrders";

Real Example:

private void btnSearch_Click(object sender, EventArgs e)
        {
            string a = "03-8月-2014";//dtpStart.Value.ToString("yyyy/MM/dd hh:mm:ss");
            string b = "05-8月-2014";//dtpEnd.Value.ToString("yyyy-MM-dd hh:mm:ss");
            gDtNursingIndexMasterResult = getTableData.getTableData("select * from NURSING_INDEX_CHECK_MASTER where CHECK_DATE Between '" + a + "' and '" + b + "'");
            gDtNursingIndexMasterResult.Tables[0].TableName = "NURSING_INDEX_CHECK_MASTER";
            gDtNursingIndexDetailResult = getTableData.getTableData("select * from NURSING_INDEX_CHECK_DETAIL where CHECK_DATE Between '" + a + "' and '" + b + "'");
            gDtNursingIndexDetailResult.Tables[0].TableName = "NURSING_INDEX_CHECK_DETAIL";

            gDtNursingIndexMasterResult.Merge(gDtNursingIndexDetailResult);

            DataTable tblMaster = gDtNursingIndexMasterResult.Tables[0].Copy();
            DataTable tblDetail = gDtNursingIndexDetailResult.Tables[0].Copy();

            gDsMasterDetail.Tables.Add(tblMaster);
            gDsMasterDetail.Tables.Add(tblDetail);

            DataColumn[] pColumns = new DataColumn[] { tblMaster.Columns["DEPT_CODE"], tblMaster.Columns["CHECK_DATE"], tblMaster.Columns["INDEX_CODE"] };
            DataColumn[] cColumns = new DataColumn[] { tblDetail.Columns["DEPT_CODE"], tblDetail.Columns["CHECK_DATE"], tblDetail.Columns["INDEX_CODE"] };
            DataRelation tDataRelation = new DataRelation("MasterDetail", pColumns, cColumns);
            gDsMasterDetail.Relations.Add(tDataRelation);

            gBsMaster.DataSource = gDsMasterDetail;
            gBsMaster.DataMember = "NURSING_INDEX_CHECK_MASTER";

            gBsDetail.DataSource = gBsMaster;
            gBsDetail.DataMember = "MasterDetail";
            bnbSearchResult.BindingSource = gBsMaster;

            cmbPatBedNo.DataBindings.Add("Text", gBsMaster, "BED_NO", true);

        }

Generating Typed DataSets Using xsd.exe

File.WriteAllText(file\employees.xsd, DataSet2.GetXmlSchema());

c:\> xsd.exe employees.xsd /d /l:cs /n:Employees.Data

c:\> csc /target:library Employees.cs

Write and Read DataSet

file.WriteAllText(file "employees.xml", employeesTable.GetXml();

DataSet key points的更多相关文章

  1. web.xml配置web中的key points(上)

    一.定义 定义时注意:xml元素是区分大小写的. <web-app></web-app> 这些必须小写 二.url-pattern 1)url-pattern 的值必须以/或者 ...

  2. Three Key Points of Success 成功三要素

    Everyone wants to be successful. Today I would like to share three simple key points of success. Num ...

  3. DataGridView key points

    Simple Examples => http://csharp.net-informations.com/datagridview/csharp-datagridview-readonly-c ...

  4. TreeView Class Key Points

    TreeView keep selected node highlighted public QualityCheck() { InitializeComponent(); //trvIndexNam ...

  5. OpenGL Shader Key Points (2)

    1.  Uniform 1.1.  Uniform变量 不是所有的变量都是跟顶点一一对应的,如变换矩阵,光源位置等. Uniform变量可以在任何类型的shader中使用,但只能作为输入值,不能在sh ...

  6. OpenGL Shader Key Points (1)

    1.  Shader起步 1.1.  可编程管线 仅考虑Vertex shader和fragment shader: 1.2.  Shader Object 在编译阶段生成,把shader源代码编译成 ...

  7. OpenGL Shader Key Points (3)

    Shader和Program Program Link过后,Shader就可以从Program中Detach并删掉.这样是不是可以节省一点点显存呢? 链接到同一个program的vertex和frag ...

  8. web.xml配置web中的key points(下)

    一.配置jsp页面 [jsp-config]中有两个子元素[taglib][jsp-property-group],注意,前者必须出现在后者之前. ①[taglib]替代jsp页面中taglib指令 ...

  9. key points & (QA) about RPKI

    @1: Q: What does ROA look like?Since ROA means which ASes are allowed for originating routes to some ...

随机推荐

  1. 微信支付v3发布到iis时的证书问题(转)

    本文纯粹转载(原地址:微信支付v3发布到iis时的证书问题 ) 一开始报“出现了内部错误” 解决方法是 方法一 var cer = new X509Certificate(certpath, pass ...

  2. Java Hour 57 Java Architecture

    Java 的架构中有4个重要的组成部分: 1 Java programming langrage 2 Java class file format 3 Java API 4 Java virtual ...

  3. Java Hour 49 保存和查询历史的Weather

    吾一直坚信,是需求的不断变化推动了架构的不断演变. 新的需求 能够查看指定日期的Weather,因为客户想要比较昨天和今天的天气情况,所以需要能够查询历史数据的功能. 1 能保存当前的天气到数据库 2 ...

  4. jq验证插件validate

    博客: http://www.cnblogs.com/linjiqin/p/3433635.html http://blog.csdn.net/windxxf/article/details/7520 ...

  5. TextView属性大全

    今天研究了TextView一天了,发现网上有一篇讲TextView属性的,非常全,收藏一下先. 发现TextView有一个比较大的问题,就是文字排版的问题,遇到数字,字母,符号等就会有问题,目前还没有 ...

  6. Hark的数据结构与算法练习之地精(侏儒)排序

    算法说明 地精排序是交换排序的一种,它是冒泡排序的一种改良,我感觉和鸡尾酒排序挺像的. 不同之处是鸡尾酒排序是从小到大,然后再从大到小切换着排序的.而地精排序是上来先从小到大排序,碰到交换到再从大到小 ...

  7. diff和common

    diff 命令 diff命令:找出两个文件的不同点,用于比较文件的差异 linux上非常重要的工具,一般用于制作补丁文件,特别是比较两个版本不同的文件以找到改动的地方. diff在命令行中打印每一个行 ...

  8. SU Demos 03T-F Analysis-03Suphasevel

    不足之处,欢迎批评指正. 1.先看readme,共有3个脚本. 第1个脚本用到的模型文件. 2.第1个脚本 运行结果 3.第2个脚本 4.第3个脚本

  9. Ready事件与Onload事件的区别

    这两种事件都是在页面文档加载时触发的,但Ready比onload先执行. 具体区别如下: 1.在Javascript中,通常使用window.onload方法. window.onload必须等到页面 ...

  10. 计算1至n中数字X出现的次数

    描述 计算 1 至 n 中数字 X 出现的次数,其中 $n \ge 1,X \in [0,9]$. 解题思路 这是一道比较简单的题目,举个例子先:假设 $n=11, X=1$,那么就是求 1, 2, ...