当前位置:网站首页>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']);
边栏推荐
- Three development trends of enterprise application from the perspective of the third technological revolution
- Win 10 mstsc connect RemoteApp
- Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
- JS - use of arguments
- SWT/ANR问题--SWT 导致 low memory killer(LMK)
- Postgresql源码(57)HOT更新为什么性能差距那么大?
- 物联网开发零基础教程
- Paramètres communs de matplotlib
- Material Design组件 - 使用BottomSheet展现扩展内容(一)
- Why is PHP called hypertext preprocessor
猜你喜欢
Linux基础 —— CentOS7 离线安装 MySQL
神经网络物联网的未来趋势与发展
纪念成为首个DAYUs200三方demo贡献者
Redis RDB snapshot
【.Net Core】程序相关各种全局文件
Future trend and development of neural network Internet of things
Material Design组件 - 使用BottomSheet展现扩展内容(一)
De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
Experience of practical learning of Silicon Valley products
PostgreSQL source code (57) why is the performance gap so large in hot update?
随机推荐
2021 RoboCom 世界机器人开发者大赛-高职组初赛
Experience of practical learning of Silicon Valley products
Glass mosaic
Create Ca and issue certificate through go language
typescript枚举
PostgreSQL notes (10) dynamically execute syntax parsing process
Redis 主从同步
硅谷产品实战学习感触
SQL optimization
通过Go语言创建CA与签发证书
Win 10 mstsc connect RemoteApp
Applet form verification encapsulation
纪念成为首个DAYUs200三方demo贡献者
What is the mosaic tailgate?
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
物联网技术应用属于什么专业分类
CADD course learning (3) -- target drug interaction
PostgreSQL source code (57) why is the performance gap so large in hot update?
Redis data types and application scenarios
Airserver latest win64 bit personal screen projection software