当前位置:网站首页>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
}
边栏推荐
- What category does the Internet of things application technology major belong to
- ShanDong Multi-University Training #3
- PyTorch学习记录
- from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘
- 使用VB.net将PNG图片转成icon类型图标文件
- Zero foundation tutorial of Internet of things development
- Current situation and future development trend of Internet of things
- kubernetes资源对象介绍及常用命令(三)
- mt管理器测试滑雪大冒险
- Stm32f030f4 drives tim1637 nixie tube chip
猜你喜欢
ARP message header format and request flow
The essence of software architecture
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
algolia 搜索需求,做的快自闭了...
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
PyCharm调用matplotlib绘图时图像弹出问题怎么解决
物联网技术应用属于什么专业分类
TS initial use, TS type
notBlank 和 notEmpty
使用 pair 做 unordered_map 的键值
随机推荐
13 MySQL-约束
边缘计算概述
2021 RoboCom 世界机器人开发者大赛-本科组初赛
Yunxin small class | common cognitive misunderstandings in IM and audio and video
Stm32f030f4 drives tim1637 nixie tube chip
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
[untitled]
【ES实战】ES上的安全性运行方式
2021 robocom world robot developer competition - preliminary competition of undergraduate group
The essence of software architecture
Current situation and future development trend of Internet of things
Practical application and extension of plain framework
ShanDong Multi-University Training #3
const // It is a const object...class nullptr_t
Notblank and notempty
vs2015 AdminDeployment.xml
golang中的iota
Openwrt enable kV roaming
【.Net Core】程序相关各种全局文件
Redis AOF log