In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 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 ASP.NET database operation", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "how to use ASP.NET database operation" bar!
DataReader of ASP.NET Database Operation Code
Role: DataReader reading class, performs "forward only" reading of data.
Read-only, forward-only data streams. Because there is only one row of data in memory at a time, using DataReader improves application performance and reduces overhead. It also provides an unbuffered data stream that allows process logic to efficiently process the results returned from the data source in sequence. Because the data is not cached in memory, DataReader is an appropriate choice when retrieving large amounts of data.
string Constrn ="uid= account;pwd= password;database= database;server= server";
SqlConnection ConnSql=new SqlConnection (strConn);
ConnSql.Open ();//Open database
string strSQL="SELECT * FROM tablename1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);SqlDataReader dr=cmd.ExecuteReader();Read();
dr.Close();Close();//Close database
ASP.NET Database Operation Code DataSet
Role: DataSet, DataAdapter reads data.
string Constrn ="uid= account;pwd= password;database= database;server= server";
SqlConnection ConnSql=new SqlConnection (strConn);
ConnSql.Open ();string strSQL="SELECT * FROM tablename1";
SqlDataAdapter da=new SqlDataAdapter(strSQL,ConnSql); DataSet ds=new DataSet();Fill(ds,"Custom Virtual Table Name");Close ();//Close database
ExecuteNonQuery of ASP.NET Database Operation Code
Function: Use ExecuteNonQuery to insert, update and delete data.
Q: What is ExecuteNonQuery?
A: In ADO. NET, ExecuteNonQuery methods are used to execute commands that do not require results, such as insert, delete, and update operations.
string Constrn ="uid= account;pwd= password;database= database;server= server";
SqlConnection ConnSql=new SqlConnection (strConn);
ConnSql.Open (); string strSQL="INSERT INTO tablename1, UPDATE tablename1 SET, Delete FROM tablename1";SqlCommand cmd=new SqlCommand (strSQL,ConnSql);ExecuteNonQuery();Close ();//Close database
ExecuteScalar of ASP.NET Database Operation Code
Role: Utilize ExecuteScalar statistics.
Q: What is ExecuteScalar?
A: ExecuteScalar method can return a single value, such as sum, total number of SQL statements and other aggregate functions.
string Constrn ="uid= account;pwd= password;database= database;server= server";
SqlConnection ConnSql=new SqlConnection (strConn);
ConnSql.Open ();//Open database
string strSQL="SELECT COUNT(*) FROM tablename1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);int intNum=(int)cmd.ExecuteScalar();Close();//Close database
Thank you for reading, the above is "ASP.NET database operation how to use" the content of the, after the study of this article, I believe that we have a deeper understanding of how to use ASP.NET database operation, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.