Is DataReader or DataSet?

xiaoxiao2021-03-06  86

Author: Jonathan Goodyear Source: Network

I often hear someone asking this question: "What should I use in the ASP.NET web application or a DataSet class?" I often see this misunderstanding in many articles and posts of the newsgroups. I think DataReader (SqlDataReader or OLEDBDATAREADER abbreviation) is better than DataSet. Sometimes I will also see the opposite statement. In fact, Microsoft created these two data access categories because they all we need. Each class has its advantages and insufficient, which you can choose to use according to the application environment. This article has made a clear story on the choice of the two, allowing you to get some guidelines when using ASP.NET to choose the DataReader class or DataSet class. These rules may change in a client-based Windows Form application environment. When I am doing these, assuming that you have used DataReader and DataSet classes and are familiar with them. Using the DataReader class is the ideal condition for using the DataReader class: The data you read must be new, so you must read from the database every time you need data. Creating a DataReader class does not consume many memory, but with the increase of the load, the performance on the DataSet will also improve quickly (refer to the article in Visual Studio Magazine in the resource). Your demand for each line is simple. The best example of this is to simply bind DataReader to a web control, such as DataGrid or DropdownList. You only need to access XML data from the database in only forward-only, read-only form. In this case, you can get an XMLReader class (equivalent to the XML version of DataRead) with the ExcecuteExmlReader () method of the SQLCommand object. This requires a SQL Server query using the for XML clause, or a NTEXT field containing a valid XML. You plan to read a few duplicate calls to the database to read a small piece of information. In this case, the performance data we mentioned earlier will have a greater improvement. Indeed, making the DataSet class more powerful features only apply to the client-based Windows Form application, such as building a relationship between multiple tables. In many cases, the DataSet category is more advantageous than the DataReader class, and in some cases, you can't use the DataReader class at all. Use the DataSet class in the following case, you should consider using the DataSet class: You build a web service, the data it uses is the data you read as the return value. Because the DataReader class must be kept to the database, they cannot be serialized into the XML, and they cannot be sent to a caller of a Web Service. You need to sort or filter data. In order to use a DataSet class to sort or filter data with a DataSet class, we use a DataSet class to sort or filter data, we try to implement these features with SQL queries (such as WHERE and ORDER BY statements) and use lighter Plated, faster DataReader class. However, sometimes it is not possible to use this method, or when you need to sort or filter data multiple times, you cannot use DataReader. For the same request, you need to traverse data multiple times. You can only loop it in DataReader. If you want to bind multiple ServerControl classes to the same dataset, choose Dataset to be better. The DataReader class cannot be bound to multiple ServerControl classes because it is only read forward.

转载请注明原文地址:https://www.9cbs.com/read-101154.html

New Post(0)