asp.net.ph

IDbCommand.CommandType Property

System.Data Namespace   IDbCommand Class


Sets or retrieves a value indicating how the CommandText property is to be interpreted.

Syntax


Script IDbCommand.CommandType [ = enumValue ]

Property Value


enumValue One of the CommandType values.

The property is read/write with a default value of Text.

Exceptions


Exception Type Condition
ArgumentException Occurs when the value was not a valid CommandType.

Remarks

When you set the CommandType property to StoredProcedure, you should set the CommandText property to the name of the stored procedure. The command executes this stored procedure when you call one of the Execute methods.

Example

The following example illustrates how the CommandType property can be set to call a procedure stored in an SQL Server™ database.


SqlConnection myConn = new SqlConnection
   ( "Data Source=localhost; Integrated Security=SSPI;" +
   "Initial Catalog=northwind" );
SqlCommand  salesCmd = new SqlCommand ( "SalesByCategory", myConn );
salesCmd.CommandType = CommandType.StoredProcedure;

SqlParameter myParam = salesCmd.Parameters.Add
   ( "@CategoryName", SqlDbType.NVarChar, 15 );
myParam.Value = "Beverages";

myConn.Open ( );
SqlDataReader myReader = salesCmd.ExecuteReader ( );
while ( myReader.Read ( ) ) {
   Response.Write ( myReader.GetString ( 0 ) + ", " + 
      myReader.GetDecimal ( 1 ) + "<br>" );
}

myReader.Close ( );
myConn.Close ( );
  C# VB

See Also

IDbCommand Members   CommandText   CommandTimeout   Connection Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph