当前位置:网站首页>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']);
边栏推荐
- cookie、session、tooken
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
- vs2015 AdminDeployment.xml
- Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
- How to display real-time 2D map after rviz is opened
- Stm32f030f4 drives tim1637 nixie tube chip
- y53.第三章 Kubernetes从入门到精通 -- ingress(二六)
- How excel opens CSV files with more than one million lines
- 物联网现状及未来发展趋势
- ADO.NET之sqlCommand对象
猜你喜欢
BlocProvider为什么感觉和Provider很相似?
云信小课堂 | IM及音视频中常见的认知误区
Practical application and extension of plain framework
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
【必会】BM41 输出二叉树的右视图【中等+】
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
Redis RDB快照
使用VB.net将PNG图片转成icon类型图标文件
Redis AOF log
Notblank and notempty
随机推荐
const // It is a const object...class nullptr_t
Is there a piece of code that makes you convinced by human wisdom
[must] bm41 output the right view of the binary tree [medium +]
Commemorate becoming the first dayus200 tripartite demo contributor
golang中的iota
TS initial use, TS type
力扣今日题-241. 为运算表达式设计优先级
PyTorch学习记录
物联网现状及未来发展趋势
Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
How excel opens CSV files with more than one million lines
ADO.NET之sqlCommand对象
有没有一段代码,让你为人类的智慧所折服
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
股票开户哪个证券公司最好,有安全保障吗
在代码中使用SqlCommand对象
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
MySQL binlog cleanup
深度学习 | 三个概念:Epoch, Batch, Iteration
Linux foundation - centos7 offline installation of MySQL