In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to analyze the relevant knowledge of ADO.NET, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
When dealing with data, ADO.NET can be divided into connected type and disconnected type.
The main objects involved in ADO.NET are:
Connection object: Connection
Command object: Command
Data reader object: DataReader
Data adapter object: DataAdapter
Dataset objects: DataSet
The following is a simple ADO.NET connected access database code
Private static void ReadOrderData (string connectionString) {string queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;"; / / use using to automatically release connection using (SqlConnection connection = new SqlConnection (connectionString)) {SqlCommand command = new SqlCommand (queryString, connection); connection.Open (); SqlDataReader reader = command.ExecuteReader () / / the default location of SqlDataReader is in front of * records. Therefore, you must call Read to start accessing any data while (reader.Read ()) {Console.WriteLine (String.Format ("{0}, {1}", reader [0], reader [1]));} / / close reader reader.Close () / / when the MARS mode of SqlConnection is turned off, only one SqlDataReader can be opened at a time. Any attempt to open another one will fail before * is closed. In addition, before reader is not closed, the same command.ExecuteReader (); will fail (whether it is MARS or not)}}
Let's give some explanation to the above code:
Code:
Console.WriteLine (String.Format ("{0}, {1}", reader [0], reader [1]))
Using the indexer of reader
The method called by the indexer is as follows:
Override public object this [int I] {get {return GetValue (I);}} override public object this [string name] {get {return GetValue (GetOrdinal (name));}}
(2) explanation of some methods of command
ExecuteNonQuery executes the Transact-SQL statement on the connection and returns the number of rows affected. (override DbCommand..::.ExecuteNonQuery (). )
ExecuteReader has been reloaded. Send CommandText to Connection and generate a SqlDataReader.
ExecuteScalar executes the query and returns the * * column of the * * row in the result set returned by the query. Ignore other columns or rows. (rewrite
DbCommand..::.ExecuteScalar (). )
ExecuteXmlReader sends CommandText to Connection and generates a XmlReader object.
(3) about connectionstring
Here are some commonly used connectionstring
/ / basic string baseconnstr= "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword"; / / MARS string marsconnstr= "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;" + "MultipleActiveResultSets=true" / / sqlexpress.mdf string mdfDataDir= "Server=.\ SQLExpress;AttachDbFilename=" in the app_data folder | DataDirectory | mydbfile.mdf; Database=dbname;Trusted_Connection=Yes; "/ / using SQL cluster failover string mirrorconnstr=" Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial Catalog=myDataBase;Integrated Security=True; "/ / Asynchronous string asynconnstr=" Server=myServerAddress Database=myDataBase;Integrated Security=True;Asynchronous Processing=True; "
In MARS, ADO.NET is actually suspended for an unclosed sqlcommand. So datareader can only use its own command instance.
The above content is how to analyze the relevant knowledge of ADO.NET. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.