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 ...
随机推荐
- ****CSS各种居中方法
水平居中的text-align:center 和 margin:0 auto 这两种方法都是用来水平居中的,前者是针对父元素进行设置而后者则是对子元素.他们起作用的首要条件是子元素必须没有被flo ...
- poj 3468 成段增减
Sample Input 10 5 1 2 3 4 5 6 7 8 9 10 Q 4 4 Q 1 10 Q 2 4 C 3 6 3 Q 2 4 Sample Output 4 55 9 15 #inc ...
- Visual Studio从此走入非Windows程序猿家
(此文章同时发表在本人微信公众号"dotNET每日精华文章") 在Build 2015大会上,微软放了很多大招,其中一个让普通(不管是微软生态还是非微软生态的)程序猿都密切关注的就 ...
- POJ2407 Relatives(欧拉函数)
题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...
- 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- Travel Problem[SZU_K28]
DescriptionAfter SzuHope take part in the 36th ACMICPC Asia Chendu Reginal Contest. Then go to QingC ...
- BZOJ3682 : Phorni
后缀平衡树+线段树. $O(1)$比较大小的标号法真是强大. #include<cstdio> #include<cmath> #define N 300010 #define ...
- BZOJ3413 : 匹配
FDUSC前刷刷题吧.. 本题每个询问就是说将询问串与主串每个后缀匹配,若匹配成功则结束,否则加上lcp的长度 对主串建立后缀树,并用主席树维护DFS序 对于每个询问串,找到最后走到的点fin_nod ...
- apple个人开发者证书无线发布app的实现(转)
解释一下这标题:apple个人开发者证书无线发布app的实现,也就是说不经过发布到app store,直接在ios设备上安装app,注:ios设备不需要越狱. 之所以有这篇文章的产生,可以看这里: 不 ...
- 洛谷 P2024 食物链 POJ 1182 Label:并查集Turbo
题目描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B 吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种,但是我 ...