当前位置:网站首页>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
}
边栏推荐
猜你喜欢
距离度量 —— 汉明距离(Hamming Distance)
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
kubernetes资源对象介绍及常用命令(三)
第六章 数据流建模
Paramètres communs de matplotlib
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
Know --matplotlib
Write some suggestions to current and future doctoral students to sort out and share
【必会】BM41 输出二叉树的右视图【中等+】
TS initial use, TS type
随机推荐
Concepts of dictionary, hash table and array
TS初次使用、ts类型
使用VB.net将PNG图片转成icon类型图标文件
Know --matplotlib
excel如何打开100万行以上的csv文件
Overview of edge calculation
使用 pair 做 unordered_map 的键值
What category does the Internet of things application technology major belong to
ShanDong Multi-University Training #3
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
Redis data types and application scenarios
软件架构的本质
ADO.NET之sqlCommand对象
cookie、session、tooken
What is the difference between memory leak and memory overflow?
y53.第三章 Kubernetes从入门到精通 -- ingress(二六)
Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
MT manager test skiing Adventure
【.Net Core】程序相关各种全局文件
Why does blocprovider feel similar to provider?