asp.net.ph

IDbCommand.Connection Property

System.Data Namespace   IDbCommand Class


Sets or retrieves the IDbConnection used by this instance of the IDbCommand.

Syntax


Script IDbCommand.Connection [ = objConnection ]

Property Value


objConnection An object representing the connection to the data source.

The property is read/write with no default value.

Exceptions


Exception Type Condition
InvalidOperationException Occurs when the Connection property is changed while a transaction is in progress.

Remarks

If you set Connection while a transaction is in progress and the Transaction property is not null, an InvalidOperationException is generated. If the Transaction property is not null and the transaction has already been committed or rolled back, Transaction is set to null.

Example

The following example illustrates how the Connection with which to execute the command can be set.

void setSqlCommand ( ) {
   string query = "SELECT * FROM Categories ORDER BY CategoryID";
   string connString = "uid=sa; pwd=; database=northwind; server=myServer";
   SqlCommand  myCmd = new SqlCommand ( query );
   myCmd.Connection = new SqlConnection ( connString );
}
  C# VB

See Also

IDbCommand Members   CommandText   CommandTimeout   CommandType 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