当前位置:网站首页>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']);
边栏推荐
- Li Kou today's question -241 Design priorities for operational expressions
- Use vb Net to convert PNG pictures into icon type icon files
- Material Design组件 - 使用BottomSheet展现扩展内容(一)
- 物联网技术应用属于什么专业分类
- 小程序表单校验封装
- 为什么PHP叫超文本预处理器
- Redis data types and application scenarios
- Redis RDB快照
- VIM color the catalogue
- 物联网应用技术专业是属于什么类
猜你喜欢

Current situation and future development trend of Internet of things

Future trend and development of neural network Internet of things

Why is PHP called hypertext preprocessor

距离度量 —— 汉明距离(Hamming Distance)

为什么PHP叫超文本预处理器

认识--Matplotlib

Development trend and future direction of neural network Internet of things

Concepts of dictionary, hash table and array

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

Redis 主从同步
随机推荐
有没有一段代码,让你为人类的智慧所折服
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
使用VB.net将PNG图片转成icon类型图标文件
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
VIM color the catalogue
URL introduction
Linux foundation - centos7 offline installation of MySQL
Daily three questions 6.28
ConcurrentSkipListMap——跳表原理
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
SQL optimization
Redis RDB snapshot
[must] bm41 output the right view of the binary tree [medium +]
神经网络物联网的发展趋势和未来方向
SWT / anr problem - SWT causes low memory killer (LMK)
Zero foundation tutorial of Internet of things development
MySQL Replication中并行复制怎么实现
What is the difference between memory leak and memory overflow?
Concurrentskiplistmap -- principle of table skipping
物联网开发零基础教程