In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the SqlCommand object in ADO.NET, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
ADO.NET after a long period of development, many users are very familiar with ADO.NET SqlCommand objects, here I would like to post a personal understanding, and discuss with you. ADO.NET provides a variety of object models, typical of which are five, all of which are classified under the System.Data.SqlClient namespace.
ADO.NET SqlCommand object
In ADO.NET, there are two ways to manipulate a database: 1. Connectionless way; 2. The way to stay connected.
Either way, you can pass commands for database operations through the methods provided by the SqlCommand object and return the results of the command execution. The general steps for operating a database while maintaining a connection are: creating an instance of SqlConnection;. Create an instance of SqlCommand; open the connection; execute the command; close the connection.
Master ADO.NET data service in seven minutes
Summary of the execution mode ADO.NET manipulation database
Summary of the Ten New Features of ADO.NET
Using Adapter to solve ADO.NET batch processing
Delve into the ADO.NET connection manager
The ADO.NET SqlCommand object provides several ways to complete operations on the database. The commonly used ExecuteNonQuery method executes the result of the SQL statement, but does not return the table data executed by the command, only the number of rows affected by the operation. The ExecuteReader,ExecuteReader method provides a fast forward-only, sequential way to read data from a database. According to the provided SELECT statement, this method returns a SqlDataReader object that can be read sequentially, and the programmer can use the Read method to cycle through the contents of each field (column) in each record. ExecuteScaler (), which is used to execute a SELECT query that returns a value, such as using the count function to calculate the number of records in the table or using the sum function to sum.
SqlConnection object
ADO.NET uses SqlConnection objects to connect to SQL Server. There are two common forms of connection strings:
1. Use Windows to integrate secure authentication, for example:
String connectionString = "IntegratedSecurity=SSPI; Database=MyDatabase.mdf;Server=localhost;"
Or:
String connectionString = "Initial Catalog= MyDataBase; Data Source=localhost;Integrated Security=SSPI;"
two。 Specify the server name, user id, user password, database name, and so on in the connection string. For example:
String connectionString = "server=localhost; uid=sa; pwd=123; database=MyDatabase.mdf"
Then create the SqlConnection object directly through the connection string, as shown in
SqlConnection conn = new SqlConnection (connectionString); this is all the content of the article "how to use SqlCommand objects in ADO.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.