ExecuteWithResults Método (StringCollection)
Executes a batch of Transact-SQL statements that return multiple result sets.
Espacio de nombres: Microsoft.SqlServer.Management.Common
Ensamblado: Microsoft.SqlServer.ConnectionInfo (en Microsoft.SqlServer.ConnectionInfo.dll)
Sintaxis
'Declaración
Public Function ExecuteWithResults ( _
sqlCommands As StringCollection _
) As DataSet()
'Uso
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[]
Parámetros
- sqlCommands
Tipo: System.Collections.Specialized. . :: . .StringCollection
A StringCollection system object value that specifies the batches of Transact-SQL statements to be executed.
Valor devuelto
Tipo: array<System.Data. . :: . .DataSet> [] () [] []
A DataSet system object array value that contains multiple result sets.
Ejemplos
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");
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 = "AdventureWorks2008R2"
$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()
}
}
}