博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DataSet key points
阅读量:6173 次
发布时间:2019-06-21

本文共 4748 字,大约阅读时间需要 15 分钟。

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 in a DataSet with data from a data source using a .

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

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

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

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

  6. Invoke the on the DataSet. Alternatively, invoke 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();

 

转载于:https://www.cnblogs.com/kevinygq/p/3886864.html

你可能感兴趣的文章
ubuntu下的dock工具
查看>>
饿了么被上海市市场监督局予以警告处分
查看>>
Java项目读取配置文件时,找不到指定的文件???
查看>>
lua/luajit and tcc
查看>>
前端安全即JS代码安全,前端源码安全探讨!
查看>>
如何快速实现异地不同网络打印机共享
查看>>
openinstall免费服务对App推广有哪些作用?
查看>>
基于Docker的微服务CI CD流水线
查看>>
学好SEO需要掌握哪些知识要点?
查看>>
JetBrains GoLand macv2019.1.2中文版如何换成无牵引模式?
查看>>
电气火灾监控系统工作原理
查看>>
中使馆驳斥《金融时报》“中国网络威胁论”
查看>>
【挨踢人物传】茶乡浪子:“传奇”职场路,一生感谢情(第12期)
查看>>
我的友情链接
查看>>
c#关于数据库连接操作的案例
查看>>
聊聊最近接触的媒体查询!
查看>>
HAproxy指南之haproxy重定向应用(案例篇)
查看>>
学习 HTTP协议挺不错的一个类
查看>>
深入字节码 -- ASM 关键接口 MethodVisitor
查看>>
linux 文件权限
查看>>