当前位置:网站首页>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']);
边栏推荐
- 2022 crane driver (limited to bridge crane) examination questions and simulation examination
- Linux foundation - centos7 offline installation of MySQL
- plain framework的实际应用和扩展
- 神经网络物联网的发展趋势和未来方向
- 【ES实战】ES上的安全性运行方式
- from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘
- CADD course learning (3) -- target drug interaction
- Stm32f030f4 drives tim1637 nixie tube chip
- 物联网技术应用属于什么专业分类
- 【.Net Core】程序相关各种全局文件
猜你喜欢

2021 RoboCom 世界机器人开发者大赛-本科组初赛

How to display real-time 2D map after rviz is opened

物联网开发零基础教程

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

Matplotlib常用設置

2022 R1 fast opening pressure vessel operation test questions and answers

Is there a piece of code that makes you convinced by human wisdom

【ES实战】ES上的安全性运行方式

The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem

Glass mosaic
随机推荐
The difference between timer and scheduledthreadpoolexecutor
【必会】BM41 输出二叉树的右视图【中等+】
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
2022 R1 fast opening pressure vessel operation test questions and answers
物联网开发零基础教程
物联网技术应用属于什么专业分类
每日三题 6.30(2)
股票开户哪个证券公司最好,有安全保障吗
【C#】依赖注入及Autofac
Redis RDB snapshot
[applet] realize the left and right [sliding] list through the scroll view component
每日三题 6.30
硅谷产品实战学习感触
上海炒股开户选择手机办理安全吗?
STM32F030F4驱动TIM1637数码管芯片
安全协议重点
SQL optimization
物联网应用技术专业是属于什么类
深度学习 | 三个概念:Epoch, Batch, Iteration
ShanDong Multi-University Training #3