Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ADO.NET SqlConnection

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use ADO.NET SqlConnection". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use ADO.NET SqlConnection.

The ADO.NET framework supports two modes of data access: connection mode (Connected) and non-connection mode (disconnected). Use Connection,Command,DataReader in ADO.NET to obtain and modify data in the database. Use the RetrieveStatistics () method to get statistics when the data command is executed, for example, to get statistics about the total command execution time.

ADO.NET SqlConnection statistics are available with the following common properties:

◆ BytesReceived: number of bytes received in the query

◆ BytesSend: the number of bytes of data sent

◆ ConnectionTime: the total time the current connection was opened

◆ ExecutionTime: returns the connection execution time in milliseconds

◆ IduCount: used to return the number of times Insert, Update, Delete commands were executed

◆ IduRows: returns the number of lines in which Insert, Update, Delete commands are executed

◆ SelectCount: used to return the number of times the Select command was executed

◆ SelectRows: used to return the number of rows executed by the Select command

ADO.NET SqlConnection case study: get the execution time of database query

The GetAll method in the / / Movies class returns a List object that can be bound by controls such as GridView as a data source binding namespace DawnDataObject {public class Movies {public static readonly string _ connectionString; / / the connection database string is a static member and shared by each instance. Static Movies () {_ connectionString = WebConfigurationManager.ConnectionStrings ["DawnEnterpriseDBConnectionString"]. The attributes included in the ConnectionString;} private string _ title; private string _ director; / / Movies class are Title, Director public string Title {get {return _ title;} set {_ title = value;}} public string Director {get {return _ director;} set {_ director = value }} / / the GetAll method in the Movies class returns a List object that can be bound by controls such as GridView as a data source binding public List GetAll (out long executeTime) / / executeTime as an out parameter {List result = new List (); SqlConnection conn = new SqlConnection (_ connectionString); SqlCommand comm = new SqlCommand ("WAITFOR DELAY '0VOVVOV03ranking select Title,Director from Movies", conn); conn.StatisticsEnabled = true / / enable using (conn) {/ / using keyword to specify that once conn leaves this code segment, its Dispose function conn.Open (); SqlDataReader reader = comm.ExecuteReader (); while (reader.Read ()) {Movies newnewmovie = new Movies (); newmovie._title = (string) reader ["Title"]; newmovie._director = (string) reader ["Director"]; result.Add (newmovie) } IDictionary stats = conn.RetrieveStatistics (); executeTime = (long) stats ["ExecutionTime"]; return result;} Thank you for reading, this is the content of "how to use ADO.NET SqlConnection". After the study of this article, I believe you have a deeper understanding of how to use ADO.NET SqlConnection, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report