当前位置:网站首页>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']);
边栏推荐
- Deep learning | three concepts: epoch, batch, iteration
- What category does the Internet of things application technology major belong to
- De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
- 电商RPA机器人,助力品牌电商抢立流量高点
- BlocProvider为什么感觉和Provider很相似?
- SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
- Current situation and future development trend of Internet of things
- Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win
- jpa手写sql,用自定义实体类接收
- Postgresql源码(58)元组拼接heap_form_tuple剖析
猜你喜欢
随机推荐
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
在代码中使用SqlCommand对象
问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
mysql:insert ignore、insert和replace区别
PyCharm调用matplotlib绘图时图像弹出问题怎么解决
Development trend and future direction of neural network Internet of things
Redis 主从同步
kubernetes资源对象介绍及常用命令(三)
物联网应用技术专业是属于什么类
[es practice] safe operation mode on ES
MySQL Replication中并行复制怎么实现
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
力扣今日题-241. 为运算表达式设计优先级
Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
Why is PHP called hypertext preprocessor
JPA handwritten SQL, received with user-defined entity classes
Redis master-slave synchronization
【C#】依赖注入及Autofac




![Various global files related to [.Net core] program](/img/89/32623abf30d3dc92a3cdb1710a624f.png)




