当前位置:网站首页>ADO.NET 之sqlConnection 对象使用摘要
ADO.NET 之sqlConnection 对象使用摘要
2022-07-01 23:23:00 【衢州小风风】
3.1 生成sqlConnection对象
string strConnection ='Data source=.;initial catalog=northwid';
sqlConnection cn = new sqlConnection(strConnection);
3.2打开sqlConnection对象
cn.Open();
3.3关闭sqlConnection对象
cn.Close();
3.4自行清除连接
使用using块,确保调用Close方法
using (sqlConnection cn = new sqlConnection(strConnection))
{
cn.Open()
}//执行到这个块时,会隐式调用Close();方法
3.5.2连接字符串生成器
SqlConnectionStringBuilder sb= new SqlConnectionStringBuilder();
sb['Datab Source'][email protected]'./SQLExpress';
sb['Initital Catalog']='Northwind';
sb['Intergrated Security']=true;
//获取字串
string strConnection = sb.ConnectionString;
3.7.1创建sqlCommand
DBCommand cmd = cn.CreateCommand();
cmd.CommandText ='select 1 + 1';
cmd.ExecuteNonQuery();
cmd.CommandText ='Insert into ...';
cmd.ExecuteNonQuery();
3.7.2开始使用sqlTransaction
sqlConnection cn = new sqlConnection(strConnection);
cn.open();
sqlTransaction tn = cn.BeginTransaction();
3.7.3获取架构信息
DataTable tb = cn.GetSchema('Tables');
foreach(DataRow row in tb.rows)
Console.Write(row['TABLE_NAME']);
边栏推荐
- 使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
- typescript枚举
- Future trend and development of neural network Internet of things
- Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
- What category does the Internet of things application technology major belong to
- CADD course learning (3) -- target drug interaction
- Practical application and extension of plain framework
- Zhao Fuquan: to ensure supply in the short term, we should build a safe, efficient and resilient supply chain in the long term
猜你喜欢
![[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing](/img/08/9ecfd53a04e147022dde3449aec132.png)
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing

Practical application and extension of plain framework

What is the mosaic tailgate?

SWT / anr problem - SWT causes kernel fuse deadlock

Commemorate becoming the first dayus200 tripartite demo contributor

What is the relationship between modeling and later film and television?

Future trend and development of neural network Internet of things

Matplotlib common charts

STM32F030F4驱动TIM1637数码管芯片

The digital summit is popular, and city chain technology has triggered a new round of business transformation
随机推荐
Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four
What is mosaic?
notBlank 和 notEmpty
Redis master-slave synchronization
STM32F030F4驱动TIM1637数码管芯片
Daily three questions 6.29
[must] bm41 output the right view of the binary tree [medium +]
距离度量 —— 汉明距离(Hamming Distance)
小程序表单校验封装
typescript枚举
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
Zhao Fuquan: to ensure supply in the short term, we should build a safe, efficient and resilient supply chain in the long term
Is there a piece of code that makes you convinced by human wisdom
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
SWT / anr problem - SWT causes low memory killer (LMK)
Postgresql随手记(10)动态执行EXECUTING语法解析过程
【ES实战】ES上的安全性运行方式
Huisheng Huiying 2022 intelligent, fast and simple video editing software
Daily three questions 6.30
Postgresql源码(57)HOT更新为什么性能差距那么大?