ADO.NET 101: SqlDataReader - SQLCommand Execution
(Page 3 of 7 )
SQLCommand's Execute Methods
The SQLCommand, prepared and ready, must be executed against the database.
However, there are several ways of executing the command,
- ExecuteReader() method returns forward only, read only, SQLDataReader.
- ExecuteScalar() retrieves a single value (first row, first column).
- ExecuteNonQuery() does not return results. For example, a stored procedure may not return values, if it is making changes to database only.
- ExecuteXMLReader() returns an XML version of the DataReader. The command has to return XML type.
In this tutorial, only the ExecuteReader() and the ExecuteXMLReader() methods of execution will be considered.
SQLCommand's ExecuteReader() Method
SQLCommand Type
In order to use the SQLDataReader, a SQLCommand is necessary. There are three SQL Command Types as seen below.

Of these three, the TableDirect type is not supported by the .NET provider for SQL. However this is supported by the OleDB providers. This will be discussed towards the end of this article. The CommandType text is usually an SQL Statement (which also happens to be the default type) and the type Stored Procedure is for a named Stored Procedure on the SQL server.
Visual Studio's Data Controls from the ToolBox can be dragged and dropped on the Design Pane and can be configured in-situ. This will be dealt with in another article. In this article, mostly code based data access procedures will be discussed. However, for rapid prototyping, and to understand the syntax without resorting to heavy reading (online or off line), the GUI-based approach is invaluable.
- CommandType:SQL Statement
- CommandType:Stored Procedure
- Simple Stored procedure:no parameters
- Stored Procedure with input parameter
- Stored Procedure with input & output parameters
Next: SQLCommand for CommandType: SQL Statement >>
More Database Articles
More By Jayaram Krishnaswamy