asp.net.ph

OleDbCommand.Connection Property

System.Data.OleDb Namespace   OleDbCommand Class


Sets or retrieves the OleDbConnection used by this instance of the OleDbCommand.

Syntax


Script OleDbCommand.Connection [ = objConnection ]

Property Value


objConnection An object representing the connection to an OLEDB 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

You cannot set the Connection, CommandType and CommandText properties if the current connection is performing an execute or fetch operation.

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 using the Connection property.

void ConnectionDemo ( ) {
   string query = "SELECT * FROM Categories ORDER BY CategoryID";
   OleDbCommand myCommand = new OleDbCommand ( query );
   myCommand.Connection = new OleDbConnection
      ( "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=Northwind.mdb" );
   myCommand.CommandTimeout = 20;
}
  C# VB

See Also

OleDbCommand 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