O'Reilly logo

ASP.NET by Example by Steven A. Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required