当前位置:网站首页>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
}
边栏推荐
- How excel opens CSV files with more than one million lines
- 2021 robocom world robot developer competition - preliminary competition of higher vocational group
- jpa手写sql,用自定义实体类接收
- 2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
- MT manager test skiing Adventure
- MySQL Replication中并行复制怎么实现
- Linux基础 —— CentOS7 离线安装 MySQL
- URL introduction
- ARP报文头部格式和请求流程
- Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
猜你喜欢

字典、哈希表、数组的概念

Kubernetes resource object introduction and common commands (III)

Commemorate becoming the first dayus200 tripartite demo contributor

Linux foundation - centos7 offline installation of MySQL

Redis RDB快照

mt管理器测试滑雪大冒险

2021 robocom world robot developer competition - preliminary competition of undergraduate group

Why does blocprovider feel similar to provider?

2021 robocom world robot developer competition - preliminary competition of higher vocational group

Redis data types and application scenarios
随机推荐
门级建模—课后习题
MySQL Replication中并行复制怎么实现
Daily three questions 6.30 (2)
Redis AOF日志
Redis AOF log
Know --matplotlib
Material Design组件 - 使用BottomSheet展现扩展内容(一)
Postgresql源码(58)元组拼接heap_form_tuple剖析
【.Net Core】程序相关各种全局文件
2021 robocom world robot developer competition - preliminary competition of higher vocational group
【ES实战】ES上的安全性运行方式
[leetcode] length of the last word [58]
y53.第三章 Kubernetes从入门到精通 -- ingress(二六)
为什么PHP叫超文本预处理器
Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
ConcurrentSkipListMap——跳表原理
RPA教程01:EXCEL自动化从入门到实操
ADO.NET 之sqlConnection 对象使用摘要
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system