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. php中base64_decode与base64_encode加密解密函数

    php中base64_decode与base64_encode加密解密函数,实例分析了base64加密解密函数的具体用法,具有一定的实用价值,需要的朋友可以参考下 本文实例讲述了php中base64_ ...

  2. poj 2082 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include ...

  3. linux下验证码无法显示:Could not initialize class sun.awt.X1 解决方案

    转自:http://my.oschina.net/xiangtao/blog/28441 网站验证码突然无法显示,并报如下错误. Caused by: java.lang.NoClassDefFoun ...

  4. SQL Server 2008 数据库同步的两种方式 (发布、订阅)

    参考转载: SQL Server 2008 数据库同步的两种方式 (发布.订阅) 使用Sqlserver事务发布实现数据同步

  5. BZOJ 1029: [JSOI2007]建筑抢修 堆+贪心

    1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...

  6. loj 1031(区间dp+记忆化搜索)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1031 思路:dp[i][j]表示从区间i-j中能取得的最大值,然后就是枚举分割点了. ...

  7. JavaScript案例五:下拉列表左右选择

    用JavaScript实现下拉列表左右选择,很简单,不过要特别注意循环时要注意变量是否发生了变化(见代码) <!DOCTYPE html> <html> <head> ...

  8. 简单修改hosts文件加快打开网页速度

    这个电脑小技巧的帖子菲菲博客分享如何通过简单一招利用修改系统的hosts文件来实现有效加快浏览器打开网页的速度.尤其是网络繁忙时DNS服务器负担加重的时候效果特别明显,有兴趣就和菲菲一起来学习一下吧, ...

  9. Mac Android签名生成keystore

    1.打开终端 2.去到java安装的根目录,即输入 cd /Library/Java/Home/bin/ 3.当前用户没有最高权限,在Library文件夹下不能生成任何文件,可以到当前用户目录下生成文 ...

  10. 如何扫描出Android系统媒体库中视频文件

    Android系统启动时会去扫描系统文件,并将系统支持的视频文件(mp4,3gp,wmv)扫描到媒体库(MediaStore)中,下面代码演示如何获得这些文件的信息: publicstatic Lis ...