Using the Command Object and DataReaders

The Command object is used to execute SQL statements against a database. The SQL statements can be ad hoc text or the name of a stored procedure in SQL Server. The SqlCommand class is responsible for SQL Server access, and the OleDbCommand class is responsible for OLE DB data sources.

You create a Command object in one of two ways:

  • By calling the CreateCommand method of a Connection object

  • By creating an instance of the SqlCommand or OleDbCommand class, and passing a valid Connection object to the Command instance

After you create a Command object, you set properties that indicate what the SQL statement is, the timeout, the connection information, and parameters if there are any in your SQL statement. ...

Get Sams Teach Yourself Visual Studio® .NET 2003 in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.