当前位置:网站首页>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']);
边栏推荐
- Who do you want to know when opening a stock account? Is it safe to open an account online?
- Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
- 2022 examination questions and online simulation examination for safety management personnel of hazardous chemical business units
- Li Kou today's question -241 Design priorities for operational expressions
- 2022安全员-C证考试题模拟考试题库及模拟考试
- 想请教股票开户要认识谁?在线开户是安全么?
- Concepts of dictionary, hash table and array
- Daily three questions 6.30
- SWT/ANR问题--SWT 导致 kernel fuse deadlock
- Daily three questions 6.29
猜你喜欢
软件架构的本质
What category does the Internet of things application technology major belong to
问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
Redis RDB快照
Know --matplotlib
Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four
神经网络物联网的发展趋势和未来方向
Is there a piece of code that makes you convinced by human wisdom
The digital summit is popular, and city chain technology has triggered a new round of business transformation
Why is PHP called hypertext preprocessor
随机推荐
Postgresql源码(58)元组拼接heap_form_tuple剖析
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
openwrt 开启KV漫游
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
有没有一段代码,让你为人类的智慧所折服
Distance measurement - Hamming distance
Matplotlib common charts
问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c
dat. GUI
plain framework的实际应用和扩展
Three development trends of enterprise application from the perspective of the third technological revolution
云信小课堂 | IM及音视频中常见的认知误区
flutter Unable to load asset: assets/images/888. png
Typescript enumeration
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
物联网开发零基础教程
2022 examination questions and online simulation examination for safety management personnel of hazardous chemical business units
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
2022 crane driver (limited to bridge crane) examination questions and simulation examination
学成在线案例实战