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 Function ExecuteScalar ( _
    sqlCommands As StringCollection _
) As Object()
‘사용 방법
Dim instance As ServerConnection 
Dim sqlCommands As StringCollection 
Dim returnValue As Object()

returnValue = instance.ExecuteScalar(sqlCommands)
public Object[] ExecuteScalar(
    StringCollection sqlCommands
array<Object^>^ ExecuteScalar(
    StringCollection^ sqlCommands
member ExecuteScalar : 
        sqlCommands:StringCollection -> Object[] 
public function ExecuteScalar(
    sqlCommands : StringCollection
) : Object[]

매개 변수

반환 값

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


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++)


$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]

참고 항목


ServerConnection 클래스

ExecuteScalar 오버로드

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

관련 자료

메서드 호출