SqlCeCommand Constructor (String, SqlCeConnection, SqlCeTransaction)

쿼리의 텍스트, SqlCeConnection, SqlCeTransaction 등을 사용하여 SqlCeCommand 클래스의 새 인스턴스를 초기화합니다.

네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe(system.data.sqlserverce.dll에 있음)

구문

‘선언
Public Sub New ( _
    commandText As String, _
    connection As SqlCeConnection, _
    transaction As SqlCeTransaction _
)
public SqlCeCommand (
    string commandText,
    SqlCeConnection connection,
    SqlCeTransaction transaction
)
public:
SqlCeCommand (
    String^ commandText, 
    SqlCeConnection^ connection, 
    SqlCeTransaction^ transaction
)
public SqlCeCommand (
    String commandText, 
    SqlCeConnection connection, 
    SqlCeTransaction transaction
)
public function SqlCeCommand (
    commandText : String, 
    connection : SqlCeConnection, 
    transaction : SqlCeTransaction
)

매개 변수

  • commandText
    쿼리 텍스트입니다.
  • connection
    데이터 원본에 대한 연결을 나타내는 SqlCeConnection입니다.
  • transaction
    SqlCeCommand가 실행되는 트랜잭션입니다.

주의

다음 표에서는 SqlCeCommand 인스턴스의 초기 속성 값을 보여 줍니다.

속성

초기 값

CommandText

cmdText

CommandType

Text

Connection

connection 매개 변수에 대한 값인 새 SqlCeConnection입니다.

관련 속성을 설정하여 이 매개 변수 모두의 값을 변경할 수 있습니다.

다음 예제에서는 SqlCeCommand를 만들고 그 속성의 일부를 설정합니다.

Dim cmdText As String = "INSERT INTO FactSalesQuota " & _
        "(EmployeeKey, TimeKey, SalesAmountQuota) " & _
        "VALUES (2, 1158, 150000.00)"

Dim conn As New SqlCeConnection("Data Source = AdventureWorks.sdf;")
conn.Open()

' Start a local transaction; SQL Mobile supports the following 
' isolation levels: ReadCommitted, RepeatableRead, Serializable
'
Dim tx As SqlCeTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)

' By default, commands run in auto-commit mode; 
'
Dim cmd As New SqlCeCommand(cmdText, conn, tx)

Try
    cmd.ExecuteNonQuery()

    ' Commit the changes to disk if everything above succeeded;
    ' Use Deferred mode for optimal performance; the changes will 
    ' be flashed to disk within the timespan specified in the 
    ' ConnectionString 'FLUSH INTERVAL' property; 
    '
    tx.Commit(CommitMode.Deferred)

    ' Alternatively, you could use:
    ' tx.Commit(CommitMode.Immediate);
    '
    ' or use default (Deferred) commit mode:
    ' tx.Commit()

Catch e As Exception
    ' Handle errors here
    '
    tx.Rollback()
Finally
    conn.Close()
End Try
string cmdText = "INSERT INTO FactSalesQuota " +
    "(EmployeeKey, TimeKey, SalesAmountQuota) " +
    "VALUES (2, 1158, 150000.00)";
        
SqlCeConnection conn = new SqlCeConnection("Data Source = AdventureWorks.sdf;");
conn.Open();

// Start a local transaction; SQL Mobile supports the following 
// isolation levels: ReadCommitted, RepeatableRead, Serializable
//
SqlCeTransaction tx = conn.BeginTransaction(IsolationLevel.ReadCommitted);

SqlCeCommand cmd = new SqlCeCommand(cmdText, conn, tx);

try
{
    cmd.ExecuteNonQuery();

      
    // Commit the changes to disk if everything above succeeded;
    // Use Deferred mode for optimal performance; the changes will 
    // be flushed to disk within the timespan specified in the 
    // ConnectionString 'FLUSH INTERVAL' property; 
    //
    tx.Commit(CommitMode.Deferred);

    // Alternatively, you could use:
    // tx.Commit(CommitMode.Immediate);
    //
    // or use default (Deferred) commit mode:
    // tx.Commit()
}
catch (Exception)
{
    // Handle errors here
    //
    tx.Rollback();
}
finally
{
    conn.Close();
}

플랫폼

개발 플랫폼

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
버전 정보
.NET Framework 및 NET Compact Framework
3.5에서 지원됨
.NET Framework
3.0에서 지원됨
.NET Compact Framework 및 .Net Framework
2.0에서 지원됨

참고 항목

참조

SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace