当前位置:网站首页>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
}
边栏推荐
- ARP报文头部格式和请求流程
- Daily three questions 6.29
- 为什么PHP叫超文本预处理器
- Matplotlib常用图表
- Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
- Various global files related to [.Net core] program
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- kubernetes资源对象介绍及常用命令(三)
- 哈工大《信息内容安全》课程知识要点和难点
- Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
猜你喜欢

写给当前及未来博士研究生一些建议整理分享

Postgresql源码(57)HOT更新为什么性能差距那么大?

【ES实战】ES上的安全性运行方式

Matplotlib常用图表

Development trend and future direction of neural network Internet of things

How to solve the image pop-up problem when pycharm calls Matplotlib to draw

Distance measurement - Hamming distance

Matplotlib common charts

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

有没有一段代码,让你为人类的智慧所折服
随机推荐
VIM color the catalogue
Know --matplotlib
问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c
Zero foundation tutorial of Internet of things development
Use vb Net to convert PNG pictures into icon type icon files
物联网技术应用属于什么专业分类
华为HMS Core携手超图为三维GIS注入新动能
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
TS初次使用、ts类型
ConcurrentSkipListMap——跳表原理
Concurrentskiplistmap -- principle of table skipping
神经网络物联网的未来趋势与发展
Matplotlib常用图表
What is the difference between memory leak and memory overflow?
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
Practical application and extension of plain framework
const // It is a const object...class nullptr_t
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
Leetcode (34) -- find the first and last positions of elements in a sorted array
JPA handwritten SQL, received with user-defined entity classes