自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

簡(jiǎn)單了解ADO.NET SqlConnection新特性

開發(fā) 后端
這里就ADO.NET SqlConnection的一些新特性簡(jiǎn)單的分析一下,文章有一個(gè)關(guān)于取得數(shù)據(jù)庫(kù)查詢的執(zhí)行時(shí)間的小案例,大家可以看看代碼的思路和過(guò)程。

ADO.NET2.0的特性想必大家也都體驗(yàn)到它的好處了,它的新特性讓你愛不釋手,所謂一分耕耘,一分收獲,付出了就一定會(huì)有回報(bào)的,說(shuō)了這么多還是希望大家多了解了解ADO.NET原理機(jī)制,我們這里就先不和大家說(shuō)關(guān)于原理的分析了,我們就ADO.NET SqlConnection的一些新特性來(lái)分析一下吧。

#T#ADO.NET框架支持兩種模式的數(shù)據(jù)訪問(wèn):連接模式(Connected)和非連接模式(disconnected)。這一節(jié)介紹如何使用連接模式訪問(wèn)數(shù)據(jù)庫(kù)中的數(shù)據(jù),利用ADO.NET中的 Connection,Command,DataReader來(lái)獲取和修改數(shù)據(jù)庫(kù)中的數(shù)據(jù) 。使用RetrieveStatistics()方法獲得數(shù)據(jù)命令執(zhí)行時(shí)的統(tǒng)計(jì)信息,例如,可以獲取總命令執(zhí)行時(shí)間的統(tǒng)計(jì)信息。

ADO.NET SqlConnection統(tǒng)計(jì)信息有以下常用屬性可以獲得:
◆BytesReceived : 查詢中接收到的字節(jié)數(shù)
◆BytesSend : 發(fā)送出數(shù)據(jù)的字節(jié)數(shù)
◆ConnectionTime : 當(dāng)前連接被開啟的總時(shí)間
◆ExecutionTime : 返回以毫秒為單位的連接執(zhí)行時(shí)間
◆IduCount: 用于返回被執(zhí)行Insert、Update、Delete命令的次數(shù)
◆IduRows : 用于返回被執(zhí)行Insert、Update、Delete命令的行數(shù)
◆SelectCount: 用于返回Select命令執(zhí)行的次數(shù)
◆SelectRows : 用于返回Select命令執(zhí)行的行數(shù)

ADO.NET SqlConnection案例分析:取得數(shù)據(jù)庫(kù)查詢的執(zhí)行時(shí)間 

  1. // Movies類中的GetAll方法返回一個(gè)List對(duì)象,該對(duì)象可以被GridView等控件做為數(shù)據(jù)源綁定  
  2. namespace  DawnDataObject  
  3. {  
  4. public class Movies  
  5. {  
  6. public static readonly string _connectionString;    
  7. // 連接數(shù)據(jù)庫(kù)字符串為靜態(tài)成員,每個(gè)實(shí)例共享。  
  8.  
  9. static Movies(){  
  10. _connectionString = WebConfigurationManager.ConnectionStrings["DawnEnterpriseDBConnectionString"].  
  11. ConnectionString;  
  12. }  
  13.  
  14. private string _title;  
  15. private string _director;  
  16.  
  17. // Movies類中包括的屬性有Title、Director  
  18. public string Title{  
  19. get { return _title; }  
  20. set { _title = value; }  
  21. }  
  22. public string Director {  
  23. get { return _director; }  
  24. set { _director = value; }  
  25. }  
  26.  
  27. // Movies類中的GetAll方法返回一個(gè)List對(duì)象,該對(duì)象可以被GridView等控件做為數(shù)據(jù)源綁定  
  28. public List<Movies> GetAll(out long executeTime)    
  29. // executeTime作為out參數(shù)  
  30. {  
  31. List<Movies> result = new List<Movies>();  
  32. SqlConnection conn = new SqlConnection(_connectionString);  
  33. SqlCommand comm = new SqlCommand("WAITFOR DELAY '0:0:03';select Title,Director from Movies", conn);  
  34. conn.StatisticsEnabled = true;   // 開啟獲取統(tǒng)計(jì)信息的功能  
  35. using(conn){  // using關(guān)鍵字指定了conn一旦離開這個(gè)代碼段,自動(dòng)調(diào)用其Dispose函數(shù)  
  36. conn.Open();  
  37. SqlDataReader reader = comm.ExecuteReader();  
  38. while(reader.Read()){  
  39. Movies newnewmovie = new Movies();  
  40. newmovie._title = (string)reader["Title"];  
  41. newmovie._director = (string)reader["Director"];  
  42. result.Add(newmovie);  
  43. }  
  44. IDictionary stats = conn.RetrieveStatistics();  
  45. executeTime = (long)stats["ExecutionTime"];  
  46. return result;  
  47. }  
  48. }  
  49. }  
責(zé)任編輯:田樹 來(lái)源: 博客
相關(guān)推薦

2009-11-04 14:17:34

ADO.NET 2.0

2009-03-12 11:26:35

Data ServicADO.NET.NET

2009-12-29 16:02:48

ADO.NET新特性

2009-12-23 10:18:21

ADO.NET 應(yīng)用程

2009-11-11 15:09:35

ADO.NET數(shù)據(jù)集

2009-12-24 09:34:47

調(diào)用ADO.NET

2009-12-29 10:26:43

ADO.NET實(shí)體框架

2009-12-29 10:36:24

ADO.NET 工具

2009-11-04 10:07:52

ADO.NET DbP

2009-12-31 14:28:09

ADO.NET參數(shù)

2009-12-21 13:59:03

ADO.NET特性

2009-11-04 13:20:28

ADO.NET Dat

2009-12-22 10:27:01

ADO.NET數(shù)據(jù)

2009-12-23 17:21:31

ADO.NET團(tuán)隊(duì)

2009-12-23 16:05:47

ADO.NET錯(cuò)誤

2009-12-30 14:59:42

ADO.NET數(shù)據(jù)集

2009-08-20 18:44:54

C#和ADO.NET

2009-11-11 12:49:29

ADO.NET框架

2009-11-13 09:13:05

2009-11-11 16:37:50

ADO.NET新增特性
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)