当前位置:网站首页>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']);
边栏推荐
- Know --matplotlib
- 使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
- PostgreSQL notes (10) dynamically execute syntax parsing process
- Material Design组件 - 使用BottomSheet展现扩展内容(一)
- Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
- 为什么PHP叫超文本预处理器
- ShanDong Multi-University Training #3
- What are the common types of points mall games?
- Future trend and development of neural network Internet of things
- Typescript enumeration
猜你喜欢

2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍

2022安全员-C证考试题模拟考试题库及模拟考试

Zhao Fuquan: to ensure supply in the short term, we should build a safe, efficient and resilient supply chain in the long term

Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry

Matplotlib common settings

物联网技术应用属于什么专业分类

The digital summit is popular, and city chain technology has triggered a new round of business transformation

Commemorate becoming the first dayus200 tripartite demo contributor

Current situation and future development trend of Internet of things
![[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
随机推荐
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
Material Design组件 - 使用BottomSheet展现扩展内容(一)
Daily three questions 6.30 (2)
【必会】BM41 输出二叉树的右视图【中等+】
Three development trends of enterprise application from the perspective of the third technological revolution
How to display real-time 2D map after rviz is opened
Practical application and extension of plain framework
物联网技术应用属于什么专业分类
Glass mosaic
Experience of practical learning of Silicon Valley products
Zhao Fuquan: to ensure supply in the short term, we should build a safe, efficient and resilient supply chain in the long term
What professional classification does the application of Internet of things technology belong to
MT manager test skiing Adventure
dat. GUI
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win
from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘
认识--Matplotlib
Practical application and extension of plain framework
[applet] realize the left and right [sliding] list through the scroll view component