Méthode ServerConnection.ExecuteWithResults (String)
Exécute une instruction Transact-SQL qui retourne un jeu de résultats.
Espace de noms : Microsoft.SqlServer.Management.Common
Assembly : Microsoft.SqlServer.ConnectionInfo (en Microsoft.SqlServer.ConnectionInfo.dll)
Syntaxe
'Déclaration
Public Function ExecuteWithResults ( _
sqlCommand As String _
) As DataSet
'Utilisation
Dim instance As ServerConnection
Dim sqlCommand As String
Dim returnValue As DataSet
returnValue = instance.ExecuteWithResults(sqlCommand)
public DataSet ExecuteWithResults(
string sqlCommand
)
public:
DataSet^ ExecuteWithResults(
String^ sqlCommand
)
member ExecuteWithResults :
sqlCommand:string -> DataSet
public function ExecuteWithResults(
sqlCommand : String
) : DataSet
Paramètres
- sqlCommand
Type : String
Valeur String qui spécifie la commande Transact-SQL à exécuter.
Valeur de retour
Type : DataSet
Valeur de l'objet système DataSet qui contient le jeu de résultats.
Exemples
C#
ServerConnection conn = new ServerConnection();
conn.DatabaseName = "AdventureWorks2012";
DataSet costData = conn.ExecuteWithResults("SELECT Name, CostRate FROM Production.Location");
DataTable infoTable = costData.Tables[0];
foreach (DataRow r in infoTable.Rows)
{
Console.WriteLine("==========================");
foreach (DataColumn c in infoTable.Columns)
{
Console.WriteLine(c.ColumnName + " = " + r[c].ToString());
}
}
PowerShell
$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.DatabaseName = "AdventureWorks2012"
$costData = $conn.ExecuteWithResults("SELECT Name, CostRate FROM Production.Location")
$infoTable = $costData.Tables[0]
foreach ($r in $infoTable.Rows)
{
Write-Host "=========================="
foreach ($c in $infoTable.Columns)
{
Write-Host $c.ColumnName "=" $r[$c].ToString()
}
}