惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
I
InfoQ
F
Full Disclosure
美团技术团队
Martin Fowler
Martin Fowler
量子位
V
V2EX
小众软件
小众软件
爱范儿
爱范儿
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
IT之家
IT之家
云风的 BLOG
云风的 BLOG
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
T
Threat Research - Cisco Blogs
T
Threatpost
P
Proofpoint News Feed
腾讯CDC
博客园 - 司徒正美
Jina AI
Jina AI
The Hacker News
The Hacker News
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 热门话题
S
Securelist
U
Unit 42
T
The Exploit Database - CXSecurity.com
博客园 - Franky
NISL@THU
NISL@THU
D
Docker
The GitHub Blog
The GitHub Blog
Latest news
Latest news
S
Schneier on Security
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
P
Palo Alto Networks Blog

博客园 - 奚彧

Siverlight 导出Excel (经测试通过 Vs2010 ,silverlight5 ) 打印代码片段 部署silverlight ria 程序 备忘 刚学 silverlight 问题遇到一堆 2010 微软难道抛弃了ado.net data service openfire 安装 关于merge .net常用代码 (收藏) - 奚彧 - 博客园 碰到一个巨郁闷的情况! - 奚彧 - 博客园 关于连接池问题 删除确认按钮 - 奚彧 - 博客园 水晶报表自动插入空白行 也谈如何缩小SQL SERVER日志文件 新年第一帖,祝大家新年快乐! vs2005什么时候能出正式版 《WEB打印的相关技术分析》 web打印2 web打印 权限设置问题!(比较着急)
关于DataSet.merge 问题的答案。
奚彧 · 2006-06-13 · via 博客园 - 奚彧

代码是关于两个dataSet 分别从不同的数据源取数据,然后进行merge 后,更新其中一个数据源

cn.Open();
                SqlCommand cmd 
= new SqlCommand(sqlAllCustomers, cn);
                SqlDataAdapter adpt 
= new SqlDataAdapter(cmd);
               

                
// Add
                DataSet dsCust1 = new DataSet();
                DataSet dsCust2 
= new DataSet();
                DataSet dsTest 
= new DataSet();
                
//adpt.AcceptChangesDuringFill = false;
                
                adpt.Fill(dsCust1, 
"TABLE1");
                
//adpt.AcceptChangesDuringFill = true;
                using (SqlConnection cnTemp = new SqlConnection(cnStrTemp))
                
{
                    
//SqlConnection cnTemp = new SqlConnection(cnStrTemp);
                    cnTemp.Open();
                    SqlCommand cmdTemp 
= new SqlCommand(sqlAllCustomers, cnTemp);
                    SqlDataAdapter adptTemp 
= new SqlDataAdapter(cmdTemp);
                    adptTemp.AcceptChangesDuringFill 
= false;
                    adptTemp.Fill(dsCust2, 
"TABLE1");
                }


                
//adpt.Update(dsCust1, "TABLE1");
                dsCust1.Merge(dsCust2);
                
                
//111
                SqlCommandBuilder objBuilder = new SqlCommandBuilder(adpt);
                
                
                adpt.UpdateCommand 
= objBuilder.GetUpdateCommand();
                adpt.InsertCommand 
= objBuilder.GetInsertCommand();
                adpt.DeleteCommand 
= objBuilder.GetDeleteCommand();

                DataTable updTable 
= dsCust1.Tables[0];
                adpt.Update(updTable.Select(
null,null, DataViewRowState.Added));

其中主要是,对被合并的数据DataAdapter 属性设置为不稳定,更新的时候将取的数据改为add状态才能更新。否则DataSet 虽然merge 了其它的DataSet 表面上虽然数据已经改变了,但是其状态仍然为稳定状态,更新将失败。