ServerConnection.ExecuteWithResults 方法 (StringCollection)
执行返回多个结果集的一批 Transact-SQL 语句。
命名空间: Microsoft.SqlServer.Management.Common
程序集: Microsoft.SqlServer.ConnectionInfo(在 Microsoft.SqlServer.ConnectionInfo.dll 中)
语法
声明
Public Function ExecuteWithResults ( _
sqlCommands As StringCollection _
) As DataSet()
用法
Dim instance As ServerConnection
Dim sqlCommands As StringCollection
Dim returnValue As DataSet()
returnValue = instance.ExecuteWithResults(sqlCommands)
public DataSet[] ExecuteWithResults(
StringCollection sqlCommands
)
public:
array<DataSet^>^ ExecuteWithResults(
StringCollection^ sqlCommands
)
member ExecuteWithResults :
sqlCommands:StringCollection -> DataSet[]
public function ExecuteWithResults(
sqlCommands : StringCollection
) : DataSet[]
参数
- sqlCommands
类型:StringCollection
一个 StringCollection 系统对象值,该值指定要执行的成批的 Transact-SQL 语句。
返回值
类型:array<DataSet[]
一个 DataSet 系统对象数组值,该值包含多个结果集。
示例
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");
DataSet[] costData = conn.ExecuteWithResults(sqlQuery);
for (int i = 0; i < costData.Length; i++)
{
foreach (DataRow r in costData[i].Tables[0].Rows)
{
Console.WriteLine("==========================");
foreach (DataColumn c in costData[i].Tables[0].Columns)
{
Console.WriteLine(c.ColumnName + " = " + r[c].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.ExecuteWithResults($sqlQuery)
for ($i = 0; $i -le $costData.Length; $i++)
{
foreach ($r in $costData[$i].Tables[0].Rows)
{
Write-Host "=========================="
foreach ($c in $costData[$i].Tables[0].Columns)
{
Write-Host $c.ColumnName "=" $r[$c].ToString()
}
}
}