SqlCeCommand Class

데이터 원본에 대해 실행할 SQL 문을 나타냅니다.

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

구문

‘선언
Public NotInheritable Class SqlCeCommand
    Inherits DbCommand
    Implements ICloneable
public sealed class SqlCeCommand : DbCommand, ICloneable
public ref class SqlCeCommand sealed : public DbCommand, ICloneable
public final class SqlCeCommand extends DbCommand implements ICloneable
public final class SqlCeCommand extends DbCommand implements ICloneable

주의

SqlCeCommand의 인스턴스가 만들어지면 초기 값에 읽기/쓰기 속성이 지정됩니다. 이러한 값에 대한 목록은 SqlCeCommand 생성자를 참조하십시오.

SqlCeCommand의 특징은 데이터 원본에서 명령을 실행하는 다음 메서드입니다.

항목

설명

ExecuteReader

행을 반환하는 명령을 실행합니다.

ExecuteNonQuery

INSERT, DELELE 및 UPDATE 문과 같은 SQL 명령을 실행합니다.

ExecuteScalar

데이터베이스에서 집계 값과 같은 단일 값을 검색합니다.

ExecuteResultSet

명령을 실행하고 결과 집합을 반환합니다.

Data Provider for SQL Server Compact 3.5에서는 일괄 쿼리를 지원하지 않습니다. 명령의 형식은 다음과 같으며

Select * from Customers 다음과 같지 않아야 합니다. Select * from Customers; Select * from Orders;

System.Data.SqlClient에서 생성된 코드를 사용하는 경우 이 제한을 따르도록 쿼리를 변경해야 할 수도 있습니다.

SQL Server Compact 3.5에서는 같은 연결을 공유하는 여러 개의 명령뿐 아니라 여러 개의 동시 연결도 지원합니다. 즉, 같은 연결에서 SqlCeDataReader의 여러 인스턴스를 가질 수 있습니다. 이 동작은 System.Data.SqlClient의 동작과 다릅니다.

SqlCeCommand를 실행하는 메서드에서 심각한 SqlCeException이 생성되면 SqlCeConnection이 끊길 수도 있습니다. 그러나 다시 연결하여 계속할 수 있습니다.

상속 계층

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DbCommand
        System.Data.SqlServerCe.SqlCeCommand

다음 예제에서는 SqlCeCommandSqlCeConnection과 함께 사용하여 데이터베이스에서 행을 선택합니다.

Dim query As String = "SELECT [Order ID], [Customer] FROM Orders"
Dim conn As New SqlCeConnection(connString)
Dim cmd As New SqlCeCommand(query, conn)

conn.Open()
Dim rdr As SqlCeDataReader = cmd.ExecuteReader()

Try
    ' Iterate through the results
    '
    While rdr.Read()
        Dim val1 As Integer = rdr.GetInt32(0)
        Dim val2 As String = rdr.GetString(1)
    End While
Finally
    ' Always call Close when done reading
    '
    rdr.Close()

    ' Always call Close when done reading
    '
    conn.Close()
End Try
string query = "SELECT [Order ID], [Customer] FROM Orders";
SqlCeConnection conn = new SqlCeConnection(connString);
SqlCeCommand cmd = new SqlCeCommand(query, conn);

conn.Open();
SqlCeDataReader rdr = cmd.ExecuteReader();

try
{
    // Iterate through the results
    //
    while (rdr.Read())
    {
        int val1 = rdr.GetInt32(0);
        string val2 = rdr.GetString(1);
    }
}
finally
{
    // Always call Close when done reading
    //
    rdr.Close();

    // Always call Close when done reading
    //
    conn.Close();
}

스레드 보안

이 유형의 모든 public static(Microsoft Visual Basic의 경우 공유) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.

플랫폼

개발 플랫폼

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 Members
System.Data.SqlServerCe Namespace
SqlCeDataAdapter
SqlCeConnection