SqlCommand 생성자

정의

SqlCommand 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
SqlCommand()

SqlCommand 클래스의 새 인스턴스를 초기화합니다.

SqlCommand(String)

쿼리 텍스트를 사용하여 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

SqlCommand(String, SqlConnection)

쿼리의 텍스트와 을 SqlCommand 사용하여 클래스의 새 인스턴스를 SqlConnection초기화합니다.

SqlCommand(String, SqlConnection, SqlTransaction)

쿼리, a 및 SqlCommand의 텍스트를 사용하여 클래스의 새 인스턴스 SqlConnectionSqlTransaction초기화합니다.

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

지정된 명령 텍스트, 연결, 트랜잭션 및 암호화 설정을 사용하여 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

SqlCommand()

SqlCommand 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlCommand();
public SqlCommand();
Public Sub New ()

예제

다음 예제에서는 속성을 SqlCommand 만들고 설정합니다 CommandTimeout .

public void CreateSqlCommand()
{
   SqlCommand command = new SqlCommand();
   command.CommandTimeout = 15;
   command.CommandType = CommandType.Text;
}
Public Sub CreateSqlCommand()
    Dim command As New SqlCommand()
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub

설명

기본 생성자는 모든 필드를 기본값으로 초기화합니다. 다음 표에서는 SqlCommand인스턴스에 대한 초기 속성 값을 보여 줍니다.

Properties 초기 값
CommandText 빈 문자열("")
CommandTimeout 30
CommandType CommandType.Text
Connection null

속성에 대한 별도의 호출을 통해 이러한 속성의 값을 변경할 수 있습니다.

추가 정보

적용 대상

SqlCommand(String)

쿼리 텍스트를 사용하여 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

public:
 SqlCommand(System::String ^ cmdText);
public SqlCommand(string cmdText);
new System.Data.SqlClient.SqlCommand : string -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String)

매개 변수

cmdText
String

쿼리 텍스트입니다.

예제

다음 예제에서는 명령 텍스트를 전달하는 />를 만듭니다.

public void CreateCommand()
 {
    string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
    SqlCommand command = new SqlCommand(queryString);
    command.CommandTimeout = 15;
    command.CommandType = CommandType.Text;
 }
Public Sub CreateCommand()
    Dim queryString As String = "SELECT * FROM Categories ORDER BY CategoryID"
    Dim command As New SqlCommand(queryString)
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub

설명

인스턴스 SqlCommand 가 만들어지면 다음 읽기/쓰기 속성이 초기 값으로 설정됩니다.

Properties 초기 값
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection 없음

속성에 대한 별도의 호출을 통해 이러한 속성의 값을 변경할 수 있습니다.

추가 정보

적용 대상

SqlCommand(String, SqlConnection)

쿼리의 텍스트와 을 SqlCommand 사용하여 클래스의 새 인스턴스를 SqlConnection초기화합니다.

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection)

매개 변수

cmdText
String

쿼리 텍스트입니다.

connection
SqlConnection

SQL Server 인스턴스에 대한 연결을 나타내는 SqlConnection.

예제

다음 예제에서는 해당 SqlCommand 속성 중 일부를 만들고 설정합니다.

private static void CreateCommand(string queryString,
    string connectionString)
{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        SqlCommand command = new SqlCommand(
            queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }
    }
}
Public Sub CreateCommand(ByVal queryString As String, _
  ByVal connectionString As String)
    Using connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)

        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader()
            While reader.Read()
            Console.WriteLine(String.Format("{0}, {1}", _
                reader(0), reader(1)))
        End While
    End Using
End Sub

설명

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

Properties 초기 값
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection 매개 변수의 값인 새 SqlConnectionconnection 입니다.

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

추가 정보

적용 대상

SqlCommand(String, SqlConnection, SqlTransaction)

쿼리, a 및 SqlCommand의 텍스트를 사용하여 클래스의 새 인스턴스 SqlConnectionSqlTransaction초기화합니다.

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection, System::Data::SqlClient::SqlTransaction ^ transaction);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection, System.Data.SqlClient.SqlTransaction transaction);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection * System.Data.SqlClient.SqlTransaction -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection, transaction As SqlTransaction)

매개 변수

cmdText
String

쿼리 텍스트입니다.

connection
SqlConnection

SQL Server 인스턴스에 대한 연결을 나타내는 SqlConnection.

transaction
SqlTransaction

SqlTransaction 실행되는 SqlCommand 개체입니다.

설명

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

Properties 초기 값
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection 매개 변수의 값인 새 SqlConnectionconnection 입니다.

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

추가 정보

적용 대상

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

지정된 명령 텍스트, 연결, 트랜잭션 및 암호화 설정을 사용하여 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection, System::Data::SqlClient::SqlTransaction ^ transaction, System::Data::SqlClient::SqlCommandColumnEncryptionSetting columnEncryptionSetting);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection, System.Data.SqlClient.SqlTransaction transaction, System.Data.SqlClient.SqlCommandColumnEncryptionSetting columnEncryptionSetting);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection * System.Data.SqlClient.SqlTransaction * System.Data.SqlClient.SqlCommandColumnEncryptionSetting -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection, transaction As SqlTransaction, columnEncryptionSetting As SqlCommandColumnEncryptionSetting)

매개 변수

cmdText
String

쿼리 텍스트입니다.

connection
SqlConnection

SQL Server 인스턴스에 대한 연결을 나타내는 SqlConnection.

transaction
SqlTransaction

SqlTransaction 실행되는 SqlCommand 개체입니다.

columnEncryptionSetting
SqlCommandColumnEncryptionSetting

암호화 설정입니다. 자세한 내용은 Always Encrypted를 참조하세요.

적용 대상