28th
2008,07
Ado.net 介绍:SqlConnection类的方法
继上一篇Ado.net 介绍:SqlConnection类的属性后再总结下SqlConnection类的方法。共12个。
1:BeginTransaction方法
此方法在连接上开始一个新的事务,返回新的SqlTransaction对象
- SqlTransaction btn = conn.BeginTransaction();
- 等价于
- SqlTransaction btn = new SqlTransaction();
- btn.Connection = conn;
- btn.Begin();
2:ChangDatebase方法
更新正在进行通信的数据库
- SqlConnection conn = new SqlConnection(strconn);
- conn.Open();
- conn.ChangDatabase("Northwind");
- 等价于
- SqlConnection conn = new SqlConnection(strconn);
- conn.Open();
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandText = "USE pubs";
- cmd.ExecuteNoQuery();
3/4:ClearPoll和ClearAllpools方法
这两个用来清除连接池的。前者清除单个。后者清队所有。
- SqlConnection.ClearPoll();
- SqlConnection.ClearAllpools();
5:Open方法
用来打开SqlConnection
- conn.Open();
6:Close方法
用来关闭SqlConnection
- conn.Close();
7:CreateCommand方法
创建SqlCommand对象
- SqlConnection conn = new SqlConnection(StrConn);
- SqlCommand cmd = conn.CreateCommand();
- 等价于
- SqlConnection conn = new SqlConnection(StrConn);
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = conn;
8/9:EnlistDistributedTransaction 方法 与 EnlistTransaction 方法
后继
10:GetSchema方法
此方法返回架构信息的DataTable
后继
11/12:RetrieveStatistics 方法 与 ResetStatistics 方法
后继
Name: Cngothic 
































Leave a reply?