In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the skills of using DataReader in ADO.NET. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.
◆ must turn off DataReader before accessing any output parameters of the relevant Command.
◆ always closes DataReader after finishing reading the data. If you use Connection only to return DataReader, close DataReader immediately after closing it.
Another way to explicitly close the Connection is to pass the CommandBehavior.CloseConnection to the ExecuteReader method to ensure that the relevant connection is closed when the ADO.NET DataReader is closed. This is especially useful if you return DataReader from a method and you cannot control the closure of DataReader or related connections.
◆ cannot remotely access DataReader between tiers. DataReader is designed for connected data access.
◆ uses typed accessors, such as GetString, GetInt32, and so on, when accessing column data. This frees you from the processing required to cast the Object returned by GetValue to a specific type.
◆ A single connection can only open one DataReader at a time. In ADO, if you open a single connection and request two recordsets that use forward-only, read-only cursors, ADO implicitly opens a second, unpooled connection to the datastore during the lifetime of the cursor, and then implicitly closes the connection. For ADO.NET, Secret does very little. If you want to open both DataReaders on the same datastore, you must explicitly create two connections, one for each DataReader. This is one way that ADO.NET provides more control over the use of pooled connections.
◆ ExecuteReader call. This changes the default behavior of DataReader to load data into memory only when requested. Note that CommandBehavior.SequentialAccess requires sequential access to the returned columns. That is, once you have read the returned column, you can no longer read its value.
If ◆ has finished reading data from DataReader but still has a large number of pending unread results, call Command's Cancel before calling DataReader's Close. Calling the Close of DataReader causes the pending results to be retrieved and the stream emptied before closing the cursor. Calling Command's Cancel discards the results on the server so that DataReader doesn't have to read them when it shuts down. If you want to return output parameters from Command, call Cancel to discard them. If you need to read any output parameters, don't call Command's Cancel, just call DataReader's Close.
Binary large object (BLOB)
When you retrieve a binary large object (BLOB) with DataReader, you should pass the CommandBehavior.SequentialAccess to the ExecuteReader method call. Because the default behavior of DataReader is to load the entire row into memory every time Read, and because the BLOB value can be very large, a large amount of memory may be used up as a result of a single BLOB. SequentialAccess sets the behavior of DataReader to load only the requested data. You can then use GetBytes or GetChars to control how much data is loaded at a time.
Remember, when using SequentialAccess, you cannot access the different fields returned by DataReader out of order. That is, if the query returns three columns, the third column is BLOB, and you want to access the data in the first two columns, you must access the value of the * column before accessing the BLOB data, and then access the value of the second column. This is because the data is now returned sequentially, and once DataReader has read it, it is no longer available.
The above is all the content of the article "what are the tips for using DataReader in ADO.NET?" Thank you for reading! Hope to share the content to help you, more related 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.