O'Reilly logo

Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition by David Sceppa

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

Using SqlCommand Objects in Code

SqlCommand objects let you execute many different types of queries. Some SqlCommand objects retrieve data in the form of a resultset, and others modify the content or structure of the data store. Let’s look at how to create SqlCommand objects and use them to perform a variety of tasks.

Creating a SqlCommand Object

You can create a SqlCommand object in three ways. The first way is simply to create an instance of an object using the new keyword and then set the appropriate properties. Second, you can use one of the available constructors to specify the query string and a SqlConnection object.

The third way is to call the CreateCommand method of the SqlConnection class (which we examined in Chapter 3). The three approaches ...

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