当前位置:网站首页>ADO. Net SqlCommand object
ADO. Net SqlCommand object
2022-07-01 23:42:00 【Quzhou Xiaofeng】
4.1 Used in code SqlCommand object
4.1.1 establish sqlCommand object
// Create without parameters
sqlCommand cmd;
cmd = new sqlCommand();
cmd.Connection = cn;
cmd.CommandText = strSQL;
// Use parameters to construct
sqlCommand cmd = new sqlCommand( strSQL.cn);
// use connection Of CreateCommand To construct the
cmd = cn.CreateCommand();
cmd.CommandText = strSQL;
4.1.3 Execute the query that returns rows
sqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "select * From ...";
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
Console.Write(dr["UserName"]);
4.1.4 Get a single value
strSQL = "select count(*) from tabname";
sqlCommandText = new sqlCommand(strSQL,cn);
int icount = (int)cmd.ExecuteScalar();
4.1.5 Execute queries that do not return result sets
strSQL ="Update table set field01=100"
sqlCommand cmd = new sqlCommand(strSQL,cn);
int iRow= cmd.ExecuteNonQuery(); // The return value is the number of rows affected , Reflect the successful implementation
4.1.6 Execute batch operation query
strSQL ="update table01 set field01 =001 .." +
"update table02 set field01 =002 .." +
"update table03 set field01 =003 .."
sqlCommand cmd = new sqlCommand(strSQL,cn);
int icount = cmd.ExecuteNonQuery();// Return the total number of rows modified by each query ,
utilize StatementCompleted Event can determine the number of rows modified by each query in batch operation
sqlCommand cmd = new sqlCommand(strSQL,cn);
cmd.StatementCompleted += new StatementCompletedEventHandler(HandleStatementCompleted);
int irow = cmd.ExcuteNonQuery();
static void HandleStatementCompleted(object sender,StatementCompletedEventArgs e)
{
int row = e.RecordCount;// The number of rows affected by each query can be reflected here
}
边栏推荐
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- [es practice] safe operation mode on ES
- notBlank 和 notEmpty
- Zero foundation tutorial of Internet of things development
- What professional classification does the application of Internet of things technology belong to
- 问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
- vs2015 AdminDeployment.xml
- Create Ca and issue certificate through go language
- SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
- ARP message header format and request flow
猜你喜欢

云信小课堂 | IM及音视频中常见的认知误区

mt管理器测试滑雪大冒险

TS initial use, TS type

物联网应用技术专业是属于什么类

from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘

使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object

ARP message header format and request flow

Stm32f030f4 drives tim1637 nixie tube chip

Development trend and future direction of neural network Internet of things

PyCharm调用matplotlib绘图时图像弹出问题怎么解决
随机推荐
Concepts of dictionary, hash table and array
物联网现状及未来发展趋势
Applet form verification encapsulation
mt管理器测试滑雪大冒险
Chapter 6 data flow modeling
神经网络物联网的发展趋势和未来方向
认识--Matplotlib
Material Design组件 - 使用BottomSheet展现扩展内容(一)
物联网技术应用属于什么专业分类
Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
Which securities company is the best to open a stock account? Is there a security guarantee
Redis AOF log
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
const // It is a const object...class nullptr_t
力扣今日题-241. 为运算表达式设计优先级
软件架构的本质
PostgreSQL source code (57) why is the performance gap so large in hot update?
vs2015 AdminDeployment.xml
Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
Redis RDB snapshot