ServerConnection.ExecuteNonQuery 메서드 (StringCollection, ExecutionTypes)

결과 집합을 반환하지 않는 지정한 실행 옵션으로 문의 일괄 처리를 실행합니다.

네임스페이스:  Microsoft.SqlServer.Management.Common
어셈블리:  Microsoft.SqlServer.ConnectionInfo(Microsoft.SqlServer.ConnectionInfo.dll)

구문

‘선언
Public Function ExecuteNonQuery ( _
    sqlCommands As StringCollection, _
    executionType As ExecutionTypes _
) As Integer()
‘사용 방법
Dim instance As ServerConnection 
Dim sqlCommands As StringCollection 
Dim executionType As ExecutionTypes 
Dim returnValue As Integer()

returnValue = instance.ExecuteNonQuery(sqlCommands, _
    executionType)
public int[] ExecuteNonQuery(
    StringCollection sqlCommands,
    ExecutionTypes executionType
)
public:
array<int>^ ExecuteNonQuery(
    StringCollection^ sqlCommands, 
    ExecutionTypes executionType
)
member ExecuteNonQuery : 
        sqlCommands:StringCollection * 
        executionType:ExecutionTypes -> int[] 
public function ExecuteNonQuery(
    sqlCommands : StringCollection, 
    executionType : ExecutionTypes
) : int[]

매개 변수

  • sqlCommands
    유형: StringCollection
    실행할 Transact-SQL 문의 일괄 처리를 지정하는 StringCollection 시스템 개체 값입니다.

반환 값

유형: array<Int32[]
sqlCommands 매개 변수로 사용되는 StringCollection 개체의 각 요소가 적용된 총 행 수를 지정하는 Int32 배열 값입니다.반환 값은 UPDATE, INSERT 및 DELETE 문의 Transact-SQL 명령이 적용된 총 행 수를 지정합니다.모든 다른 유형의 문인 경우 반환 값은 -1입니다.

주의

일괄 처리의 실행 Transact-SQL일반적으로 결과 집합을 반환 하지 않는 문. 이들은 일반적으로데이터 정의언어 (DDL) 문 또는 저장된 프로시저를 서버 설정에 영향을.

Text의속성은 CapturedSql개체의 실행을 허용 하는 매개 변수로 사용할 수 있습니다 캡처된 Transact-SQL문.

StringCollection로 사용 되는 개체는 sqlCommands매개 변수는일괄 처리구분 기호에 의해 구분 된 여러 개의 일괄 처리를 포함할 수 있습니다. 기본적으로일괄 처리구분 기호 이동, 하지만 함께집합수 있는 BatchSeparator속성. 일괄 처리 실행은 제어는 executionType매개 변수 합니다.

SQLCMD 명령에 의해 인식 되는 ExecuteNonQuery메서드. 경우는 sqlCommand매개 변수 그건 하지 SQLCMD 명령메서드실패 후 고 문을 포함 ExecutionFailureException예외가 발생 하지 않는 한은 executionType매개 변수를 포함 하도록집합되었습니다는 ExecutionTypes.ContinueOnError 값.

VB

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Set the execution mode to CaptureSql for the connection.
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql
'Make a modification to the server that is to be captured.
srv.UserOptions.AnsiNulls = True
srv.Alter()
'Iterate through the strings in the capture buffer and display the captured statements.
Dim s As String
For Each s In srv.ConnectionContext.CapturedSql.Text
    Console.WriteLine(s)
Next
'Execute the captured statements.
srv.ConnectionContext.ExecuteNonQuery(srv.ConnectionContext.CapturedSql.Text)
'Revert to immediate execution mode. 
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server
$srv.ConnectionContext.SqlExecutionModes = [Microsoft.SqlServer.Management.Common.SqlExecutionModes]::CaptureSql
$srv.UserOptions.AnsiNulls = $TRUE
$srv.Alter()
foreach ($s in $srv.ConnectionContext.CapturedSql.Text)
{
   Write-Host $s
}
$srv.ConnectionContext.ExecuteNonQuery($srv.ConnectionContext.CapturedSql.Text)
$srv.ConnectionContext.SqlExecutionModes = [Microsoft.SqlServer.Management.Common.SqlExecutionModes]::ExecuteSql

참고 항목

참조

ServerConnection 클래스

ExecuteNonQuery 오버로드

Microsoft.SqlServer.Management.Common 네임스페이스

관련 자료

캡처 모드 사용