当前位置:网站首页>Using SqlCommand objects in code
Using SqlCommand objects in code
2022-07-01 23:43: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
}
边栏推荐
- Kubernetes resource object introduction and common commands (III)
- 13 MySQL-约束
- Applet form verification encapsulation
- 小程序表单校验封装
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- ARP message header format and request flow
- ShanDong Multi-University Training #3
- SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
- 2021 RoboCom 世界机器人开发者大赛-本科组初赛
- 电商RPA机器人,助力品牌电商抢立流量高点
猜你喜欢

How to display real-time 2D map after rviz is opened

Overview of edge calculation

华为HMS Core携手超图为三维GIS注入新动能

Redis data types and application scenarios

问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c

ARP message header format and request flow

物联网现状及未来发展趋势

MT manager test skiing Adventure

第六章 数据流建模

使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
随机推荐
Zero foundation tutorial of Internet of things development
.env.xxx 文件,加了常量,却undefined
Concurrentskiplistmap -- principle of table skipping
JPA handwritten SQL, received with user-defined entity classes
Future trend and development of neural network Internet of things
转行软件测试,知道这四点就够了!
Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
为什么PHP叫超文本预处理器
哈工大《信息内容安全》课程知识要点和难点
Write some suggestions to current and future doctoral students to sort out and share
Know --matplotlib
Which securities company is the best to open a stock account? Is there a security guarantee
PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
Matplotlib common charts
cookie、session、tooken
Kubernetes resource object introduction and common commands (III)
[leetcode] length of the last word [58]
Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
电商RPA机器人,助力品牌电商抢立流量高点
Matplotlib常用設置