문서를 영문으로 보려면 영문 확인란을 선택하세요. 마우스 포인터를 텍스트 위로 이동시켜 팝업 창에서 영문 텍스트를 표시할 수도 있습니다.
번역
영문

ServerConnection.ExecuteReader 메서드 (String)

Executes Transact-SQL statements that return one or multiple result sets.

네임스페이스:  Microsoft.SqlServer.Management.Common
어셈블리:  Microsoft.SqlServer.ConnectionInfo(Microsoft.SqlServer.ConnectionInfo.dll)

public SqlDataReader ExecuteReader(
	string sqlCommand
)

매개 변수

sqlCommand
유형: System.String
A String value that specifies the Transact-SQL command to be executed.

반환 값

유형: System.Data.SqlClient.SqlDataReader
A SqlDataReader object value that contains one or more result sets.

The SqlDataReader object is returned to let the client process the data without requiring it to read all information into memory.

C#

ServerConnection conn = new ServerConnection();
conn.DatabaseName = "AdventureWorks2012";
SqlDataReader reader = conn.ExecuteReader("SELECT Name, CostRate FROM Production.Location");
while (reader.Read())
{
   string name = (string)reader["Name"];
   decimal cRate = (decimal)reader["CostRate"];
   Console.WriteLine(name + "(" + cRate + ")");
}
reader.Close();

PowerShell

$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.DatabaseName = "AdventureWorks2012"
$reader = $conn.ExecuteReader("SELECT Name, CostRate FROM Production.Location")
while ($reader.Read())
{
   $name = $reader.GetValue(0);
   $cRate = $reader.GetValue(1);
   Write-Host $name,"(",$cRate,")"
}
$reader.Close()

커뮤니티 추가 항목

추가
표시: