当前位置:网站首页>ADO. Net SqlConnection object usage summary
ADO. Net SqlConnection object usage summary
2022-07-01 23:42:00 【Quzhou Xiaofeng】
3.1 Generate sqlConnection object
string strConnection ='Data source=.;initial catalog=northwid';
sqlConnection cn = new sqlConnection(strConnection);
3.2 open sqlConnection object
cn.Open();
3.3 close sqlConnection object
cn.Close();
3.4 Self clearing connection
Use using block , Make sure to call Close Method
using (sqlConnection cn = new sqlConnection(strConnection))
{
cn.Open()
}// When this block is executed , Will implicitly call Close(); Method
3.5.2 Connection string generator
SqlConnectionStringBuilder sb= new SqlConnectionStringBuilder();
sb['Datab Source'][email protected]'./SQLExpress';
sb['Initital Catalog']='Northwind';
sb['Intergrated Security']=true;
// Get string
string strConnection = sb.ConnectionString;
3.7.1 establish sqlCommand
DBCommand cmd = cn.CreateCommand();
cmd.CommandText ='select 1 + 1';
cmd.ExecuteNonQuery();
cmd.CommandText ='Insert into ...';
cmd.ExecuteNonQuery();
3.7.2 Start using sqlTransaction
sqlConnection cn = new sqlConnection(strConnection);
cn.open();
sqlTransaction tn = cn.BeginTransaction();
3.7.3 Get schema information
DataTable tb = cn.GetSchema('Tables');
foreach(DataRow row in tb.rows)
Console.Write(row['TABLE_NAME']);
边栏推荐
- Redis AOF log
- [untitled]
- 神经网络物联网的发展趋势和未来方向
- 2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
- 物联网技术应用属于什么专业分类
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- What is the difference between memory leak and memory overflow?
- Commemorate becoming the first dayus200 tripartite demo contributor
- golang中的iota
- SWT / anr problem - SWT causes kernel fuse deadlock
猜你喜欢
![[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing](/img/08/9ecfd53a04e147022dde3449aec132.png)
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing

有没有一段代码,让你为人类的智慧所折服

使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object

Redis AOF log

Why is PHP called hypertext preprocessor

Paramètres communs de matplotlib

物联网技术应用属于什么专业分类

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

Redis RDB snapshot

软件架构的本质
随机推荐
图的遍历之深度优先搜索和广度优先搜索
深度学习 | 三个概念:Epoch, Batch, Iteration
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
字典、哈希表、数组的概念
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
ADO.NET之sqlCommand对象
PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
Matplotlib常用图表
Concepts of dictionary, hash table and array
物联网应用技术专业是属于什么类
Is there a piece of code that makes you convinced by human wisdom
dat. GUI
PostgreSQL source code (57) why is the performance gap so large in hot update?
2021 robocom world robot developer competition - preliminary competition of undergraduate group
SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
【必会】BM41 输出二叉树的右视图【中等+】
Redis RDB快照
Notblank and notempty
Windows 7 安装MYSQL 错误:1067
PyCharm调用matplotlib绘图时图像弹出问题怎么解决