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 ...
随机推荐
- 记32位Oracle客户端登录报12560协议适配器错误的解决办法
国庆买了一台新电脑ThinkPad E431,i5双核CPU,8G内存,硬盘比较坑爹5400转的500G,重点是预装win8的64位简体中文版.大学时买了第一台电脑神舟笔记本,因为神舟电脑便宜,所以没 ...
- FileHelper-文件操作辅助类
using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Whir.S ...
- (三)WebRTC手记之本地视频采集
转自:http://www.cnblogs.com/fangkm/p/4374610.html 前面两篇文章介绍WebRTC的运行流程和使用框架接口,接下来就开始分析本地音视频的采集流程.由于篇幅较大 ...
- CC2540开发板学习笔记(六)——AD控制(自带温度计)
一.实验目的 将采集的内部温度传感器信息通过串口发送到上位机 二.实验过程 1.寄存器配置 ADCCON1(0XB4)ADC控制寄存器1 BIT7:EOC ADC结束标志位0:AD转换进行中 ...
- 转载:关于Matlab GUI的一些经验总结
去年做了一些关于Matlab GUI的程序,现在又要做相关的东西,回想起来,当时很多经验没有记录下来,现在回顾起来始终觉得不爽,所以从现在开始,一定要勤写记录. 从简单的例子说起吧. 创建Matlab ...
- HealthKit开发快速入门教程之HealthKit开发概述简介
HealthKit开发快速入门教程之HealthKit开发概述简介 2014年6月2日召开的年度开发者大会上,苹果发布了一款新的移动应用平台,可以收集和分析用户的健康数据.该移动应用平台被命名为“He ...
- ZOJ 3603 DP LCS
已经5年没有做OJ了, 曾经沧海难为水,除去巫山不是云" 准备每周刷1-2题! 题目大意:给出N个字符串,且各个字符串都包含唯一的字母,即不存在"ABCA"(A重复了), ...
- OI再见
以下是一只蒟蒻的回忆: 1.进入高一 小县城不重视OI,直到进了高中才知道有OI这个东西,于是我就开始了OI…(看,够弱的吧,相信你是小学就开始学了) 学了几天Pascal语法后,被老师报上了NOIP ...
- c++ namespace的使用
** namespace:命名空间就是为解决C++中的变量.函数的命名冲突而服务的. ** namespace定义的格式基本格式是: namespace identifier { entitie ...
- Log4j日志级别
日志记录器(Logger)是日志处理的核心组件.log4j具有5种正常级别(Level). 日志记录器(Logger)的可用级别Level (不包括自定义级别 Level), 以下内容就是摘自log4 ...