SqlCeCommand 생성자 (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 _
)
‘사용 방법
Dim commandText As String
Dim connection As SqlCeConnection
Dim transaction As SqlCeTransaction

Dim instance As New SqlCeCommand(commandText, _
    connection, transaction)
public SqlCeCommand(
    string commandText,
    SqlCeConnection connection,
    SqlCeTransaction transaction
)
public:
SqlCeCommand(
    String^ commandText, 
    SqlCeConnection^ connection, 
    SqlCeTransaction^ transaction
)
new : 
        commandText:string * 
        connection:SqlCeConnection * 
        transaction:SqlCeTransaction -> SqlCeCommand
public function SqlCeCommand(
    commandText : String, 
    connection : SqlCeConnection, 
    transaction : SqlCeTransaction
)

매개 변수

주의

다음 표에서는 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();
        }

참고 항목

참조

SqlCeCommand 클래스

SqlCeCommand 오버로드

System.Data.SqlServerCe 네임스페이스