다음을 통해 공유


SqlBatchCommand 생성자

정의

오버로드

SqlBatchCommand()

SqlBatchCommand를 초기화합니다.

SqlBatchCommand(String, CommandType, IEnumerable<SqlParameter>, SqlCommandColumnEncryptionSetting)

SqlBatchCommand를 초기화합니다.

SqlBatchCommand()

SqlBatchCommand를 초기화합니다.

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

예제

다음 예제에서는 및 SqlBatch를 만든 SqlConnection 다음 일괄 처리에 여러 SqlBatchCommand 개체를 추가합니다. 그런 다음 일괄 처리를 실행하여 를 만듭니다 SqlDataReader. 이 예제에서는 일괄 처리 명령의 결과를 읽고 콘솔에 기록합니다. 마지막으로, 이 예제에서는 를 닫은 다음 SqlConnection 블록이 using scope 떨어지면 을 닫습니다SqlDataReader.

using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        string str = "Data Source=(local);Initial Catalog=Northwind;"
        + "Integrated Security=SSPI;Encrypt=False";
        RunBatch(str);
    }

    static void RunBatch(string connString)
    {
        using var connection = new SqlConnection(connString);
        connection.Open();

        var batch = new SqlBatch(connection);

        const int count = 10;
        const string parameterName = "parameter";
        for (int i = 0; i < count; i++)
        {
            var batchCommand = new SqlBatchCommand($"SELECT @{parameterName} as value");
            batchCommand.Parameters.Add(new SqlParameter(parameterName, i));
            batch.BatchCommands.Add(batchCommand);
        }

        // Optionally Prepare
        batch.Prepare();

        var results = new List<int>(count);
        using (SqlDataReader reader = batch.ExecuteReader())
        {
            do
            {
                while (reader.Read())
                {
                    results.Add(reader.GetFieldValue<int>(0));
                }
            } while (reader.NextResult());
        }
        Console.WriteLine(string.Join(", ", results));
    }
}

적용 대상

SqlBatchCommand(String, CommandType, IEnumerable<SqlParameter>, SqlCommandColumnEncryptionSetting)

SqlBatchCommand를 초기화합니다.

public SqlBatchCommand (string commandText, System.Data.CommandType commandType = System.Data.CommandType.Text, System.Collections.Generic.IEnumerable<Microsoft.Data.SqlClient.SqlParameter> parameters = default, Microsoft.Data.SqlClient.SqlCommandColumnEncryptionSetting columnEncryptionSetting = Microsoft.Data.SqlClient.SqlCommandColumnEncryptionSetting.UseConnectionSetting);
new Microsoft.Data.SqlClient.SqlBatchCommand : string * System.Data.CommandType * seq<Microsoft.Data.SqlClient.SqlParameter> * Microsoft.Data.SqlClient.SqlCommandColumnEncryptionSetting -> Microsoft.Data.SqlClient.SqlBatchCommand
Public Sub New (commandText As String, Optional commandType As CommandType = System.Data.CommandType.Text, Optional parameters As IEnumerable(Of SqlParameter) = Nothing, Optional columnEncryptionSetting As SqlCommandColumnEncryptionSetting = Microsoft.Data.SqlClient.SqlCommandColumnEncryptionSetting.UseConnectionSetting)

매개 변수

commandText
String

SqlBatchCommand의 텍스트입니다.

commandType
CommandType

속성을 해석하는 방법을 CommandText 나타냅니다.

parameters
IEnumerable<SqlParameter>

개체의 SqlParameter 컬렉션은 를 만드는 SqlParameterCollection데 사용됩니다.

columnEncryptionSetting
SqlCommandColumnEncryptionSetting

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

적용 대상