Метод 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
)
public:
array<Object^>^ ExecuteScalar(
StringCollection^ sqlCommands
)
member ExecuteScalar :
sqlCommands:StringCollection -> Object[]
public function ExecuteScalar(
sqlCommands : StringCollection
) : Object[]
Параметры
- sqlCommands
Тип: System.Collections.Specialized. . :: . .StringCollection
A StringCollection system object value that specifies the batches of Transact-SQL statements to be executed.
Возвращаемое значение
Тип: array<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 = "AdventureWorks2008R2";
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 = "AdventureWorks2008R2"
$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++
}
См. также