Поделиться через


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)

Syntax

'Declaration
Public Property Connection As SqlCeConnection
'Usage
Dim instance As SqlCeCommand
Dim value As SqlCeConnection

value = instance.Connection

instance.Connection = value
public SqlCeConnection Connection { get; set; }
public:
property SqlCeConnection^ Connection {
    SqlCeConnection^ get ();
    void set (SqlCeConnection^ value);
}
/** @property */
public SqlCeConnection get_Connection ()

/** @property */
public void set_Connection (SqlCeConnection value)
public function get Connection () : SqlCeConnection

public function set Connection (value : SqlCeConnection)
Not applicable.

Property Value

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

Exceptions

Exception type Condition

InvalidOperationException

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

Remarks

SQL Server Compact Edition 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).

Example

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

Dim queryText As String = "SELECT * FROM Categories ORDER BY [Category ID]"
Dim cmd As New SqlCeCommand(queryText)

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

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

Platforms

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0, 1.0

See Also

Reference

SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace
CommandText
CommandTimeout
CommandType