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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - James_Chen

SEO站内优化(On-page SEO) 一个逗号引发的IE7 Jquery Ajax失效 CSS IE6/IE7/IE8/FireFox CSS 兼容办法 hack - James_Chen Chromium书签同步无法连接到服务器的解决办法 jquery ajax 乱码解决 does not contain a definition for 80072745 80072efd 解决办法 FLASH ActionScript2.0 读取WebService数据 实现将dataset已有的一个datatable重新排序(转) ASP.NET程序中常用的三十三种代码 - James_Chen - 博客园 DataGridView 在程序集中找到无效的ServicedComponent派生类。 Cookie常用 - James_Chen - 博客园 regasm regsvcs区别 8004EOOF错误 - James_Chen - 博客园 声明了属性后,可像使用类的字段那样使用这些属性。 - James_Chen - 博客园 给BindingNavigator加个保存按钮 DateSet和BindingNavigator合作的产物 C#中计算两个时间的差
Visual Studio 2005 中的 TableAdapter
James_Chen · 2006-06-20 · via 博客园 - James_Chen

jiels - by - 06 六月, 2006 03:38

Me.EmployeesTableAdapter.FillByCountryAndCity ( _
Me.NorthwindDataSet.Employees, Me.CountryListbox.SelectedValue.Trim(), 
_ Me.CityTextbox.Text.Trim() )

举一个简单的代码片断示例会有助于解释这些特性。在 Visual Studio 2002/2003 中,即使使用了类型化 DataSet,执行一个带有两个参数的简单查询也需要不少的代码。对于下列查询

SELECT FirstName, LastName from Employees WHERE Country = @country AND City = @city

我们必须按以下方式编写代码:

Me.SqlAdapter1.SelectCommand.Parameters ("@country").value =     
Me.CountryListbox.SelectedValue.Trim()   
Me.SqlAdapter1.SelectCommand.Parameters (
"@city").value =     
Me.CityTextbox.Text.Trim()   
Me.SqlAdapter1.Fill (Me.NorthwindDataSet.Employees)

毫无疑问,随着参数数量的增长,代码行数也将不断增加。但更重要的是,正确地记忆和输入所有参数名的机率却大大降低了。即使准确记住了参数名,也仍然需要记住参数的数据类型。这还不是最糟糕的情况,如果错误地输入了字段名或者为值赋了错误的类型,那么很可能到运行时才会察觉。

如果使用 Visual Studio 2005 中的 TableAdapter,一旦定义了命令 FillByCountryAndCity,在任何地方使用它时只需编写一行代码,将其以参数值形式传递即可:

Me.EmployeesTableAdapter.FillByCountryAndCity ( _
   Me.NorthwindDataSet.Employees, Me.CountryListbox.SelectedValue.Trim(), 
      _    Me.CityTextbox.Text.Trim() )