当前位置:网站首页>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
}
边栏推荐
- Material Design组件 - 使用BottomSheet展现扩展内容(一)
- 安全协议重点
- Paramètres communs de matplotlib
- 学成在线案例实战
- ARP message header format and request flow
- mysql:insert ignore、insert和replace区别
- Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
- from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
- De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
- What is the difference between memory leak and memory overflow?
猜你喜欢

Redis AOF log

Redis 主从同步

安全协议重点

Use vb Net to convert PNG pictures into icon type icon files

Is there a piece of code that makes you convinced by human wisdom

SWT / anr problem - SWT causes kernel fuse deadlock

Matplotlib常用設置

认识--Matplotlib

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

Stm32f030f4 drives tim1637 nixie tube chip
随机推荐
第六章 数据流建模
问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c
RPA教程01:EXCEL自动化从入门到实操
安全协议重点
【.Net Core】程序相关各种全局文件
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
字典、哈希表、数组的概念
Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win
2021 robocom world robot developer competition - preliminary competition of higher vocational group
使用VB.net将PNG图片转成icon类型图标文件
TS初次使用、ts类型
物联网开发零基础教程
What is the difference between memory leak and memory overflow?
为什么PHP叫超文本预处理器
URL introduction
Daily three questions 6.28
What category does the Internet of things application technology major belong to
Redis AOF log
Postgresql源码(58)元组拼接heap_form_tuple剖析
股票开户哪个证券公司最好,有安全保障吗