Datasheet

The three main methods of the command you'll use are the execute methods:
In the examples so far, we haven't used these methods as the execution of the command is handled
transparently for us. You'll see the
ExecuteReader() method in action when you look at the
DataReader, and the ExecuteNonQuery() method in action in the next chapter.
The Parameters Collection
A parameter is an unknown value – a value that ADO.NET doesn't know until the page is being run,
and is often used to filter data based upon some user value. For example, consider a page showing a list
Method Description
ExecuteNonQuery()
This executes the command but doesn't return any data.
It is useful for commands that perform an action, such as
updating data, but don't need to return a value.
ExecuteReader()
This executes the command and returns a
DataReader object.
ExecuteScalar()
This executes the command and returns a single value.
Property Description
CommandText
Contains the SQL command or the name of a stored
procedure.
Indicates the type of command being run, and can be one of
the CommandType enumeration values, which are:
StoredProcedure
To indicate a stored procedure is
being run.
TableDirect
To indicate the entire contents of
a table are being returned. In this
case, the CommandText property
should contain the table name.
This value only works for Oledb
connections.
CommandType
Text
To indicate a SQL text command.
This is the default value.
Connection
The Connection object being used to connect to a database.
Parameters
A collection or Parameter objects, which are used to pass
details to and from the command.
272
Chapter 8
57084_08.qxp 30/01/2004 8:03 PM Page 272