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

What are the ADO.NET objects?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly talks about "what are the ADO.NET objects?". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what ADO.NET objects have.

ADO.NET is a new technology of Microsoft database access, which supports two schemes: connected access and disconnected access. ADO.NET defines a set of interfaces IDbConnection, IDbCommand, IDbDataAdapter, and IDDataReader, and there are abstract classes that display these interfaces: DbConnection, DbCommand, DbDataAdapter, and DataReader; vary from database vendor to implement these interfaces.

The ◆ ADO.NET object Connection:Connection object has two properties: ConnectionString and State;, and two important methods: Open and close.

The ◆ ADO.NET object Command:Command object has one property: CommandType (sql statement or stored procedure); three important methods: ExecuteNonQuery (number of rows affected by adding, deleting or changing) and ExecuteReader (returning DataReader object type) ExecuteScalar (returns * * row * * column value of the result set)

◆ ADO.NET object DataReader:DataReader object cannot be instantiated directly, but must be created by a method in the Command object; DataReader has many properties, Read (whether there is the next piece of data), and properties for reading data (three ways)

◆ ADO.NET object DataAdapter: acts as an adapter; there is an important method, Fill, which can manipulate data without opening a database connection

◆ ADO.NET object DataSet: equivalent to a database in memory, populating DataSet or DataTable with DataAdapter objects

◆ ADO.NET object DataTable (DataColumn object and DataRow object): it has two properties, Columns and Rows

Parameterized SQL statement:

Sql2005 query method:

/ / instantiate Connection object SqlConnection connection = new SqlConnection ("Data Source= (local); Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa"); / / instantiate Command object SqlCommand command = new SqlCommand ("select * from UserInfo where sex=@sex and age > @ age", connection); / / * examples of adding query parameters command.Parameters.AddWithValue ("@ sex", true) / / the second example of adding query parameters SqlParameter parameter = new SqlParameter ("@ age", SqlDbType.Int); / / Note that the age field in the UserInfo table is parameter.Value = 30 of type int; command.Parameters.Add (parameter); / / add parameters / / instantiate DataAdapter SqlDataAdapter adapter = new SqlDataAdapter (command); DataTable data = new DataTable ()

Placeholder:

Paging query: first calculate the total number of rows, and then calculate how many pages

First of all:

Int count = int.Parse (command.ExecuteScalar () .ToString ())

Secondly:

Page= (m% n) = = 0? (page=): (m/n+1)

N is the number of rows displayed per page

* *:

Select top 5 * from UserInfo where UserId not in (select top (NMel 1) * 5 UserID from UserInfo order by UserID asc) order by UserID asc here, I believe you have a deeper understanding of "what are the ADO.NET objects", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 281

*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