当前位置:网站首页>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
}
边栏推荐
- Daily three questions 6.30
- Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
- How to display real-time 2D map after rviz is opened
- 2021 RoboCom 世界机器人开发者大赛-高职组初赛
- 为什么PHP叫超文本预处理器
- RPA教程01:EXCEL自动化从入门到实操
- .env.xxx 文件,加了常量,却undefined
- [untitled]
- SWT / anr problem - SWT causes low memory killer (LMK)
- 字典、哈希表、数组的概念
猜你喜欢

Practical application and extension of plain framework

神经网络物联网的发展趋势和未来方向

.env.xxx 文件,加了常量,却undefined

Redis AOF log

神经网络物联网的未来趋势与发展

PostgreSQL source code (57) why is the performance gap so large in hot update?

The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem

Door level modeling - after class exercises

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

Future trend and development of neural network Internet of things
随机推荐
为什么PHP叫超文本预处理器
Is there a piece of code that makes you convinced by human wisdom
Create Ca and issue certificate through go language
from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘
Applet form verification encapsulation
Material Design组件 - 使用BottomSheet展现扩展内容(一)
ConcurrentSkipListMap——跳表原理
安全协议重点
Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
Matplotlib常用設置
.env.xxx 文件,加了常量,却undefined
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
Kubernetes resource object introduction and common commands (III)
2021 RoboCom 世界机器人开发者大赛-高职组初赛
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
Li Kou today's question -241 Design priorities for operational expressions
Experience of practical learning of Silicon Valley products
Distance measurement - Hamming distance
kubernetes资源对象介绍及常用命令(三)