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

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - Laser.NET

WumiiRelatedItems C#创建一个线程为什么会消耗那么多的内存? 【跨平台的.NET解决方案】-Mono越来越成熟! [转]英语中符号以及标点符号的读法(或许对查看英文资料的人有些帮助) 06年中国互联网调查结果之:网民上网经常使用的网络服务 让短信更好的为企业服务!——短消息交互平台简介 GoF Patterns [ASP.NET2.0]一个方便使用的在线截图Web控件-WebImageMaker [转]经典的几个网络签名:) [原创] 我的生活我安排,我的调度我做主!——介绍一个 日程安排/工作计划/任务调度 的Scheduling组件。(二) [原创] 我的生活我安排,我的调度我做主!——介绍一个 日程安排/工作计划/任务调度 的Scheduling组件。(一) [ADO.NET]由数据库触发器引发的问题 [转] IE的bug列表 [C#语言] C#语言中又一个自认为不太理想的地方。。。 [辅助工具] 一个方便将ASP代码升级到ASP.NET的小工具 -- ASP Code Migrator! 关于ASP.NET页面嵌入代码的高亮显示的问题。 [C#语言] C#语法中一个很奇怪的地方:) 这样的网站,2个月是否可能?? [新手点滴] C# vs VB.NET 哪个好?
[新手点滴] IDbCommand.Prepare()方法。
Laser.NET · 2006-03-06 · via 博客园 - Laser.NET

今天在逛新闻组的时候无意中看到了SqlCommand.Prepare()方法。在IDbCommand接口上就定义了Prepare()方法,这个方法可以把CommandType为Text的SQL语句提前在数据库中编译为一个临时的StoredProcedure然后再执行,这样对于需要多次执行的DbCommand来说,可以提高一定的执行效率:)注意:请在指定了Command的Connection之后再调用Prepare()方法。

此方法在msdn上的介绍如下:

Creates a prepared (or compiled) version of the command on the data source.

Remarks

If the CommandType property is set to TableDirect, Prepare does nothing. If CommandType is set to StoredProcedure, the call to Prepare should succeed, although it may result in a no-op.

Example
The following example creates an instance of the derived class, OleDbCommand, and opens the connection. The example then prepares a stored procedure on the data source by passing a string that is a SQL Select statement and a string to use to connect to the data source.
[C#]

public void OleDbCommandPrepareEx() {
   
int  id = 20;
   
string  desc = "myFirstRegion" ;
   OleDbConnection rConn 
= new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");
   rConn.Open();
   OleDbCommand command    
= new OleDbCommand(null, rConn);

   
// Create and prepare an SQL statement.
   command.CommandText = "insert into Region (RegionID, RegionDescription) values (@id, @desc)" ;
   command.Parameters.Add ( 
"@id", id) ;
   command.Parameters.Add ( 
"@desc", desc) ;
   command.Prepare() ;  
// Calling Prepare after having set the Commandtext and parameters.
   command.ExecuteNonQuery();

   
// Change parameter values and call ExecuteNonQuery.
   command.Parameters[0].Value = 21;
   command.Parameters[
1].Value = "mySecondRegion";
   command.ExecuteNonQuery();
}