DataSet key points
In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in turn, updating the original data are to:
Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter.
Change the data in individual DataTable objects by adding, updating, or deleting DataRow objects.
Invoke the GetChanges method to create a second DataSet that features only the changes to the data.
Call the Update method of the DataAdapter, passing the second DataSet as an argument.
Invoke the Merge method to merge the changes from the second DataSet into the first.
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的更多相关文章
- web.xml配置web中的key points(上)
一.定义 定义时注意:xml元素是区分大小写的. <web-app></web-app> 这些必须小写 二.url-pattern 1)url-pattern 的值必须以/或者 ...
- Three Key Points of Success 成功三要素
Everyone wants to be successful. Today I would like to share three simple key points of success. Num ...
- DataGridView key points
Simple Examples => http://csharp.net-informations.com/datagridview/csharp-datagridview-readonly-c ...
- TreeView Class Key Points
TreeView keep selected node highlighted public QualityCheck() { InitializeComponent(); //trvIndexNam ...
- OpenGL Shader Key Points (2)
1. Uniform 1.1. Uniform变量 不是所有的变量都是跟顶点一一对应的,如变换矩阵,光源位置等. Uniform变量可以在任何类型的shader中使用,但只能作为输入值,不能在sh ...
- OpenGL Shader Key Points (1)
1. Shader起步 1.1. 可编程管线 仅考虑Vertex shader和fragment shader: 1.2. Shader Object 在编译阶段生成,把shader源代码编译成 ...
- OpenGL Shader Key Points (3)
Shader和Program Program Link过后,Shader就可以从Program中Detach并删掉.这样是不是可以节省一点点显存呢? 链接到同一个program的vertex和frag ...
- web.xml配置web中的key points(下)
一.配置jsp页面 [jsp-config]中有两个子元素[taglib][jsp-property-group],注意,前者必须出现在后者之前. ①[taglib]替代jsp页面中taglib指令 ...
- key points & (QA) about RPKI
@1: Q: What does ROA look like?Since ROA means which ASes are allowed for originating routes to some ...
随机推荐
- Linux snmp监控
http://blog.csdn.net/apple_llb/article/details/50494787 http://www.ttlsa.com/monitor/snmp-oid/
- 使用ASP.NET Web API自带的类库实现对CORS的支持(在开发中使用这种方式)(转载)
在<通过扩展让ASP.NET Web API支持W3C的CORS规范>中我们通过自定义的HttpMessageHandler为ASP.NET Web API赋予了跨域资源共享的能力,具体来 ...
- hdu 1061 快速幂
求n^n的个位 Sample Input 2 3 4 Sample Output 7 6 直接快速幂了,注意要用long long #include<cstdio> long long q ...
- Oracle多个服务各代表什么作用(转)
在Windows 操作系统下安装Oracle 9i时会安装很多服务——并且其中一些配置为在Windows 启动时启动.在Oracle 运行在Windows 下时,它会消耗很多资源,并且有些服务可能我们 ...
- 前端调试效率低?试试这10个“Chrome开发者工具”使用技巧
摘要:今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试,优化页面渲染速度等.希望能提升Web开发人员的工作效率. 今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试, ...
- C++primer学习笔记(二)——Chapter 4
4.1 Fundamentals 1.Basic Concepts (1)操作符分为一元,二元或者三元操作符: (2)复杂的表达式中含有很多操作符时: 规则一:分为不同的级别,级别高的先运行: 规则 ...
- HttpSession--会话
- BZOJ3847 : ZCC loves march
注意到集结操作相当于合并一些点 于是我们可以使用并查集 对于每一行.每一列维护一个链表,储存里面的点 查询x时,在并查集中找到x的祖先u,此时x的坐标就是u的坐标 然后扫描u所在行列的链表,依次删除每 ...
- 【POJ】3261 Milk Patterns
http://poj.org/problem?id=3261 题意:一个长度为n的串,要求最长的子串的长度且这个子串的出现次数不少于k次.(1<=n<=20000, 2<=k< ...
- hiho#14
军训去了没有打,回来看题跑. T1:hehe 注意X可能是实数233 #include<cstdio> #include<cctype> #include<queue&g ...