当前位置:网站首页>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']);
边栏推荐
- [must] bm41 output the right view of the binary tree [medium +]
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- How to solve the image pop-up problem when pycharm calls Matplotlib to draw
- 常见的积分商城游戏类型有哪些?
- 距离度量 —— 汉明距离(Hamming Distance)
- 图的遍历之深度优先搜索和广度优先搜索
- PostgreSQL source code (57) why is the performance gap so large in hot update?
- Is there a piece of code that makes you convinced by human wisdom
- Redis RDB snapshot
- Current situation and future development trend of Internet of things
猜你喜欢

第六章 数据流建模

Redis data types and application scenarios

Development trend and future direction of neural network Internet of things

Notblank and notempty

门级建模—课后习题

MT manager test skiing Adventure

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

from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘

Use vb Net to convert PNG pictures into icon type icon files

使用VB.net将PNG图片转成icon类型图标文件
随机推荐
Concepts of dictionary, hash table and array
ADO.NET之SqlDataAdpter对象
golang中的iota
JPA handwritten SQL, received with user-defined entity classes
What category does the Internet of things application technology major belong to
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
Postgresql源码(58)元组拼接heap_form_tuple剖析
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
SWT / anr problem - SWT causes low memory killer (LMK)
RPA教程01:EXCEL自动化从入门到实操
JS - use of arguments
Various global files related to [.Net core] program
jpa手写sql,用自定义实体类接收
2021 robocom world robot developer competition - semi finals of higher vocational group
SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
ShanDong Multi-University Training #3
Kubernetes resource object introduction and common commands (III)
2021 robocom world robot developer competition - preliminary competition of higher vocational group
Postgresql源码(57)HOT更新为什么性能差距那么大?
第六章 数据流建模