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

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - 克仔

克仔嘅第一次。。。“浮潜” Exact ADC之Paintball大戦 - 克仔 - 博客园 .NET Compact Framework里的DateTimePicker Control显示錯误的month selection list .NET CF v1的Form.ShowDialog(Me)里的Me在不能用了! .NET CF里的toolbar image在Windows Mobile 2003 SE消失了。 先嚟為《達文西的密碼》電影熱熱身。 汽油起價 - 加油站車龍。 我嘅第一部O2 Xda ll mini 《達文西的密碼》登上大银幕 Single Instance Appplication in .NET CF 丹•布朗 《數字城堡》 全新ARM base PocketPC 2003 Emulator Beta 已登場。 向左走,向右走? 全新旅途。。。 如何在ASP.NET里用HtmlInputFile控件来上载文件。 達文西的密碼 - 後記。 達文西的密碼。 如何用ASP.NET里的State Management Database来储存Session Variable。 如何用SqlConnection类的InfoMessage事件来显示Stored Procedure的PRINT讯息。 Deamon Tool
如何用DataSet.GetChanges来提升数据库资料更新效率。
克仔 · 2005-04-12 · via 博客园 - 克仔

(華版)

一般我们都是直接用回同一个DataSet来更新数据库里的资料,但有没有想过这样是很没有效率的做法!因为SqlDataAdapter要扫描整个DataSet里的数据的RowState;只有以下三个State的数据才传送回去数据库:
   DataRowState.Added
   DataRowState.Deleted
   DataRowState.Modified

 

所以就要用DataSet.GetChanges方法来读取所指定(Added,Deleted或Modified)的数据,然后存到另一个新的DataSet(比如说:dsChanges)。这一来,当执行SqlDataAdapter.Update方法时就不再需要扫描那么多的数据了(比如说:Unchanged的DataRow)。

而且每一个DataRow都会保存两份数据;一份是原本的数据(在还没有更改时)和更改后的数据(RowState = DataRowState.Modified)。这也是SqlDataAdapter用来面对数据conflict时的重点数据。因为DataSet是保存在用户端的数据(就是ADO.NET的设计重点"Disconnected Environment");所以存在数据库里的数据随时都可以被另一个程序更改而没有反映在别的用户端里的DataSet。

如果没有了Original的数据,那SqlDataAdapter里的UpdateCommand的CommandText就如以下:

  UPDATE Customers SET ContactName = @ContactName WHERE CustomerID = @CustomerID

但是如果有了Original的数据后;整个CommandText就会复杂多了(尤其是那些读取整个table的数据那种!)和更加保险:

   UPDATE Customers SET ContactName = @ContactName WHERE CustomerID = @CustomerID AND ContactName = @OrigContactName

而@ContactName就是读取自DataRow.Item("ContactName", DataRowVersion.Current)和@OrigContactName就读取自DataRow.Item("ContactName", DataRowVersion.Original)。当然SqlDataAdapter.UpdateCommand里的CommandText就会复杂多一些了。。。


點撃下載代碼