문서를 영문으로 보려면 영문 확인란을 선택하세요. 마우스 포인터를 텍스트 위로 이동시켜 팝업 창에서 영문 텍스트를 표시할 수도 있습니다.
번역
영문

ServerConnection.ExecuteScalar 메서드 (StringCollection)

Executes a batch of Transact-SQL statements and returns the first column of the first row as an object value.

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

public Object[] ExecuteScalar(
	StringCollection sqlCommands
)

매개 변수

sqlCommands
유형: System.Collections.Specialized.StringCollection
A StringCollection system object value that specifies the batches of Transact-SQL statements to be executed.

반환 값

유형: System.Object[]
An object array value that specifies the first column of the first row for each result set.

C#

ServerConnection conn = new ServerConnection();
conn.DatabaseName = "AdventureWorks2012";
StringCollection sqlQuery = new StringCollection();
sqlQuery.Add("SELECT Name FROM Production.Location");
sqlQuery.Add("SELECT CostRate FROM Production.Location");
Object[] costData = conn.ExecuteScalar(sqlQuery);
for (int i = 0; i < costData.Length; i++)
{
   Console.WriteLine(costData[i].ToString());
}

PowerShell

$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.DatabaseName = "AdventureWorks2012"
$sqlQuery = new-object System.Collections.Specialized.StringCollection
$sqlQuery.Add("SELECT Name FROM Production.Location")
$sqlQuery.Add("SELECT CostRate FROM Production.Location")
$costData = $conn.ExecuteScalar($sqlQuery)
$i = 0
while ($i -le $costData.Length)
{
   Write-Host $costData[$i]
   $i++
}

커뮤니티 추가 항목

추가
표시: