ServerConnection.ExecuteScalar 方法 (String)
Executes a Transact-SQL statement 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 ( _
sqlCommand As String _
) As Object
用法
Dim instance As ServerConnection
Dim sqlCommand As String
Dim returnValue As Object
returnValue = instance.ExecuteScalar(sqlCommand)
public Object ExecuteScalar(
string sqlCommand
)
public:
Object^ ExecuteScalar(
String^ sqlCommand
)
member ExecuteScalar :
sqlCommand:string -> Object
public function ExecuteScalar(
sqlCommand : String
) : Object
参数
- sqlCommand
类型:System.String
A String value that specifies the Transact-SQL command to be executed.
返回值
类型:System.Object
An Object system object value that specifies the first column of the first row of the result set.
示例
C#
ServerConnection conn = new ServerConnection();
conn.DatabaseName = "AdventureWorks2012";
costData = conn.ExecuteScalar("SELECT CostRate FROM Production.Location");
Console.WriteLine(costData.ToString());
PowerShell
$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.DatabaseName = "AdventureWorks2012"
$reader = $conn.ExecuteScalar("SELECT CostRate FROM Production.Location")
Write-Host $reader