Using the SqlDataReader Class
Posted by ~Ray @ 2007-11-17 22:03:35
Using the SqlDataReader Class (Page 1 of 6 )If you read any of my previous ADO. NET articles you will find that I used the SqlDataReader class in many of the examples. Today we will communicate more about the SqlDataReader class and use its methods and properties. Some of you may wonder how the SqlDataReader class gets find to the fields using the array-like syntax; we will talk about that as come up.
If you are not familiar with C# Indexers please consult my bind for a.
If you are not familiar with the SqlDataReader categorise you should know that it's one of the players on the ADO. NET team of data access classes. We undergo the SqlConnection class which is used to create and open a connection to the database using the connection string that you provide and we undergo the SqlCommand class which is used to execute a T-SQL statement like decide. attach. UPDATE or DELETE and stored procedures against a database using the connection opened by the SqlConnection disapprove and retrieve the result.
As you might know one of the methods of the SqlCommand class is used to retrieve an object of write SqlDataReader; this is the SqlCommand. ExecuteReader() method. The SqlDataReader is what you are going to use to retrieve data -- to the client for example or to a business component like the ObjectDataSource hold back which we are going to discuss in the next few articles along with the SqlDataSource class.
The SqlDataReader retrieves the data in a read-only forward-only mechanism. Read-only means that you can't use the SqlDataReader categorise to execute statements that update the data in your databases. Forward-only means that you don't have find to the previous row once you have read it; the SqlDataReader class retrieves the row discards it and then retrieves the next row and so on. You undergo find to the fields of the current row using indexers.
A column-ordinal based indexer uses the column number to retrieve the field's data as in myDataReader[0]. And a string-based indexer uses the column name to access its handle's determine. Usually you would use the string column-name based indexer because it eliminates any confusion about what field you are retrieving. You would create verbally something like myDataReader["LastName"]. But it's faster to use the column-ordinal based indexer because the data reader will not perform any additional operations to retrieve the field's determine; it will just go to the column ordinal you be to find and get the value. With the string column-name based indexer however as in myDataReader["LastName"] the SqlDataReader has to examine for a column with that name and then returns its value which slows the performance a bit.
Let's see an example that uses the SqlDataReader class. Note that we are using the SQL Server. NET Data Provider for all the examples.
FileHold Express is an affordable software product for small business or departments that demand a feature rich enter management solution. FileHold Express is an entry inform for companies who wish to start small but add more users and documents over time. Customers may easily grade from FileHold Express to the Enterprise version.
The HelpConnection. NET solution is a end web-based CRM (Customer Relations Management) system. It is a client information knowledgebase book and communication system! This is an Enterprise Level application that has been built to evaluate heavy merchandise loads lots of data and still retain speed.
This whitepaper describes how Microsoft’s scalable and integrated database platform can help companies of all sizes securely store and manage ever-increasing amounts of data from disparate sources. Microsoft's solution can also help verify that business-critical systems and applications stay up and running.
This document discusses things to consider when architecting a large high-performance relational data warehouse especially one that is entertain to unpredictable ad hoc queries. The discussion includes some of the new features of SQL Server 2005 and considerations to take into account when using these features.
connect this webcast to hit the books how security is implemented in Microsoft SQL Server 2005. We discuss security from the perspective of the server the database and database objects and review the different options you can use at each level to help secure your data. See how familiar security concepts such as encryption are implemented in this release.
This video highlights how easy it is to use Microsoft’s complete and tightly integrated solution that couples the familiarity and enhanced visualization of Excel with the rich capabilities of SQL Server 2005 to create meaningful business intelligence.
Alpha Five is software for building desktop and web database applications - applications that include report writing intelligent email web connectivity backend database find data browsers and security. Alpha Five users inform that applications can be built 5 to 10 times faster than with other tools.
Get up to 3 hours of award-winning SQL Server 2005 training from AppDev -- remove! You'll get up to go with step-by-step instruction by industry experts hands-on lab exercises sample code printable courseware ($115 determine). furnish not available in some countries. Get your free CD or transfer now.
Q4bis is a very powerful yet very intuitive and easy to use Business Intelligence. Data Analysis and a Self Service reporting drive for companies running J. D Edwards. SAP and any other ERP package. It is a adjust SQL based BI / data warehousing solution for a lot less money!
Attunity Connect is standards-based integration middleware for accessing mainframe enterprise data sources and legacy applications. Attunity Connect offers a real-time enjoin integration solution providing SQL and XML based find through standard interfaces. [ADVERTHERE]Related article:
http://www.aspfree.com/c/a/ASP.NET/Using-the-SqlDataReader-Class/
0 Comments:
No comments have been posted yet!
|