Retrieving Data

Now that you've seen how to connect to the database, it's time to start issuing commands. The easiest way to send commands to the database is with the SqlCommand object.

Using the SqlCommand Object

The SqlCommand object contains all the functionality that you will need to issue Select, Insert, Update, and Delete statements. The SqlCommand object can return a DataReader, giving you the ability to iterate through the result set return from a Select. Finally, a SqlCommand allows you to call stored procedures, specifying the input and output arguments, and providing access to the return value.

Executing SQL Statements

Listing 4.2 shows the SqlCommand object in action.

Listing 4.2. Retrieving data using the SqlCommand.
 // // Connect ...

Get ASP.NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.