Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘SqlDataReader’

Multiple Result Sets Processing in Ado.net

About ADO.Net Multiple ResultSet Processing Example

In this Example, we will see packing more than one SQL statement in a SqlCommand and process it through the SqlDataReader object. From the past articles on ado.net we are already familiar with Connection, Command and Reader objects. Hence, we will focus on dealing with multiple result sets.

The example retrieves the data from the SQL Server sample database Pubs. A total number of authors queried from the table authors is displayed in a label control marked as 1 and author name from the same table is displayed in the combo box item marked as 2. The list box marked as 3 displays all store names by querying the table stores from the Pubs database. When we click the Get Data button (Marked as 4), the example fetches all the data through a single SqlCommand formed by three SQL statements.

Continue Reading →

Ado.Net SqlCommand Example

ExecuteReader ExecuteNonQuery ExecuteScalar Block Diagram

To fetch data from the database, we need DB connection. In ADO.Net, based on the Database Provider, there are distinct connection classes. For example, to hook up to an Oracle Database we need to use OracleConnection and in the same way we need SqlConnection to hook up to the SQL Server database. The Command Object is also database specific. For Example, SqlCommand object can talk with SQL Server DB through SqlConnection object and OracleCommand object can talks to the Oracle DB through OracleConnection. These command objects know what needs to be executed in the database. In this article, we will study how to use SqlCommand and its methods ExecuteScalar, ExecuteReader and ExecuteNonQuery.

Continue Reading →