Export (0) Print
Expand All

SqlCeCommand.Connection Property

Gets or sets the SqlCeConnection used by this instance of the SqlCeCommand.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

public SqlCeConnection Connection { get; set; 
/** @property */
public SqlCeConnection get_Connection ()

/** @property */
public void set_Connection (SqlCeConnection value)

public function get Connection () : SqlCeConnection

public function set Connection (value : SqlCeConnection)

Property Value

The connection to a data source. The default value is a null reference (Nothing in Visual Basic).

Exception typeCondition

InvalidOperationException

The Connection property was changed while a transaction was in progress.

SQL Server Mobile supports multiple simultaneous connections as well as multiple commands sharing the same connection. Thus, it is possible to have multiple instances of SqlCeDataReader open on the same connection. This behavior differs from that of System.Data.SqlClient.

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 a null reference (Nothing in Visual Basic), an InvalidOperationException is generated. If the Transaction property is not a null reference (Nothing in Visual Basic) and the transaction has already been committed or rolled back, Transaction is set to a null reference (Nothing in Visual Basic).

The following example creates a SqlCeCommand and sets the Connection property to a SqlCeConnection object.

string queryText = "SELECT * FROM Categories ORDER BY [Category ID]";
SqlCeCommand cmd = new SqlCeCommand(queryText);

cmd.Connection = conn;
cmd.CommandType = CommandType.Text;

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft