当前位置:网站首页>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']);
边栏推荐
- 软件架构的本质
- 2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
- Key points and difficulties of the course "information content security" at Harbin Institute of Technology
- notBlank 和 notEmpty
- Matplotlib common charts
- cookie、session、tooken
- 图的遍历之深度优先搜索和广度优先搜索
- 写给当前及未来博士研究生一些建议整理分享
- Redis data types and application scenarios
- golang中的iota
猜你喜欢
Why is PHP called hypertext preprocessor
Door level modeling - after class exercises
Matplotlib常用設置
Is there a piece of code that makes you convinced by human wisdom
【ES实战】ES上的安全性运行方式
Distance measurement - Hamming distance
PostgreSQL source code (57) why is the performance gap so large in hot update?
PyTorch学习记录
距离度量 —— 汉明距离(Hamming Distance)
问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
随机推荐
Concepts of dictionary, hash table and array
哈工大《信息内容安全》课程知识要点和难点
Create Ca and issue certificate through go language
Linux基础 —— CentOS7 离线安装 MySQL
云信小课堂 | IM及音视频中常见的认知误区
Matplotlib common charts
SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
Redis RDB快照
转行软件测试,知道这四点就够了!
安全协议重点
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
【C#】依赖注入及Autofac
Future trend and development of neural network Internet of things
Redis data types and application scenarios
PyTorch学习记录
距离度量 —— 汉明距离(Hamming Distance)
有没有一段代码,让你为人类的智慧所折服