Share via


SqlDataSource 생성자

정의

SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

오버로드

SqlDataSource()

SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

SqlDataSource(String, String)

지정된 연결 문자열과 Select 명령을 사용하여 SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

SqlDataSource(String, String, String)

지정된 연결 문자열과 Select 명령을 사용하여 SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

SqlDataSource()

SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlDataSource();
public SqlDataSource ();
Public Sub New ()

추가 정보

적용 대상

SqlDataSource(String, String)

지정된 연결 문자열과 Select 명령을 사용하여 SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlDataSource(System::String ^ connectionString, System::String ^ selectCommand);
public SqlDataSource (string connectionString, string selectCommand);
new System.Web.UI.WebControls.SqlDataSource : string * string -> System.Web.UI.WebControls.SqlDataSource
Public Sub New (connectionString As String, selectCommand As String)

매개 변수

connectionString
String

내부 데이터베이스에 연결하는 데 사용되는 연결 문자열입니다.

selectCommand
String

내부 데이터베이스에서 데이터를 검색하는 데 사용되는 SQL 쿼리입니다. SQL 쿼리가 매개 변수가 있는 SQL 문자열인 경우 Parameter 개체를 SelectParameters 컬렉션에 추가해야 합니다.

예제

다음 코드 예제에서는 만드는 방법을 보여 줍니다.는 SqlDataSource 사용 하 여 제어는 SqlDataSource 생성자입니다. 예제에는 일반적이 지 않습니다.는 SqlDataSource 제어 되는 중간 계층 개체의 구현 되지만 Web Forms 페이지에 없는 비즈니스 개체에 대 한 간단 하 게 데이터베이스와 상호 작용할 수 있습니다. 이 예제에서는 Web.config 파일에 저장 된 연결 문자열을 사용 합니다.

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ObjectDataSource 클래스입니다.

// Returns a collection of NorthwindEmployee objects.
public static ICollection GetAllEmployees () {
  ArrayList al = new ArrayList();

  ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

  SqlDataSource sds
    = new SqlDataSource(cts.ConnectionString, "SELECT EmployeeID FROM Employees");

  try {

    IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

    // Iterate through the Enumeration and create a
    // NorthwindEmployee object for each ID.
    foreach (DataRowView row in IDs) {
      string id = row["EmployeeID"].ToString();
      NorthwindEmployee nwe = new NorthwindEmployee(id);
      // Add the NorthwindEmployee object to the collection.
      al.Add(nwe);
    }
  }
  finally {
    // If anything strange happens, clean up.
    sds.Dispose();
  }

  return al;
}
' Returns a collection of NorthwindEmployee objects.
Public Shared Function GetAllEmployees() As ICollection
   Dim al As New ArrayList()

   Dim cts As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("NorthwindConnection")
   Dim sds As New SqlDataSource(cts.ConnectionString, "SELECT EmployeeID FROM Employees")
   Try
      Dim IDs As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)

      ' Iterate through the Enumeration and create a
      ' NorthwindEmployee object for each ID.
      For Each row As DataRowView In IDs
         Dim id As String = row("EmployeeID").ToString()
         Dim nwe As New NorthwindEmployee(id)
         ' Add the NorthwindEmployee object to the collection.
         al.Add(nwe)
      Next
   Finally
      ' If anything strange happens, clean up.
      sds.Dispose()
   End Try

   Return al
End Function 'GetAllEmployees

설명

데이터베이스 제품 마다 다양 한 SQL 구문 사용 하므로 selectCommand 는 현재 사용 중인 ADO.NET 공급자를 식별 되는 종속 된 ProviderName 속성입니다. SQL 문자열이 매개 변수가 있는 쿼리나 명령인 경우 매개 변수의 자리 표시자도 사용 중인 ADO.NET 공급자에 따라 달라집니다. 예를 들어 공급자가 합니다 System.Data.SqlClient에 대 한 기본 공급자 인를 SqlDataSource 클래스는 매개 변수의 자리 표시자는 '@parameterName'. 그러나 공급자로 설정 된 경우는 System.Data.Odbc 또는 System.Data.OleDb, 매개 변수의 자리 표시자는 '?'합니다. 매개 변수가 있는 SQL 쿼리 및 명령에 대 한 자세한 내용은 참조 하세요. SqlDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

SelectCommand 값일 수는 SQL 문자열이 나 저장된 프로시저의 이름을 데이터 원본에서 저장된 프로시저를 지 원하는 경우.

추가 정보

적용 대상

SqlDataSource(String, String, String)

지정된 연결 문자열과 Select 명령을 사용하여 SqlDataSource 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlDataSource(System::String ^ providerName, System::String ^ connectionString, System::String ^ selectCommand);
public SqlDataSource (string providerName, string connectionString, string selectCommand);
new System.Web.UI.WebControls.SqlDataSource : string * string * string -> System.Web.UI.WebControls.SqlDataSource
Public Sub New (providerName As String, connectionString As String, selectCommand As String)

매개 변수

providerName
String

SqlDataSource에서 사용하는 데이터 공급자의 이름입니다. 공급자를 설정하지 않은 경우 SqlDataSource는 기본적으로 Microsoft SQL Server용 ADO.NET 공급자를 사용합니다.

connectionString
String

내부 데이터베이스에 연결하는 데 사용되는 연결 문자열입니다.

selectCommand
String

내부 데이터베이스에서 데이터를 검색하는 데 사용되는 SQL 쿼리입니다. SQL 쿼리가 매개 변수가 있는 SQL 문자열인 경우 Parameter 개체를 SelectParameters 컬렉션에 추가해야 합니다.

설명

데이터베이스 제품 마다 다양 한 SQL 구문 사용 하므로 selectCommand 는 현재 사용 중인 ADO.NET 공급자를 식별 되는 종속 된 providerName 매개 변수입니다. SQL 문자열이 매개 변수가 있는 쿼리나 명령인 경우 매개 변수의 자리 표시자도 사용 중인 ADO.NET 공급자에 따라 달라집니다. 예를 들어 공급자가 System.Data.SqlClient에 대 한 기본 공급자 인 합니다 SqlDataSource 클래스는 매개 변수의 자리 표시자는 '@parameterName'합니다. 그러나 공급자로 설정 된 경우는 System.Data.Odbc 또는 System.Data.OleDb, 매개 변수의 자리 표시자는 '?'합니다. 매개 변수가 있는 SQL 쿼리 및 명령에 대 한 자세한 내용은 참조 하세요. SqlDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

SelectCommand 속성 수는 SQL 문자열이 나 저장된 프로시저의 이름을 데이터 원본에서 저장된 프로시저를 지 원하는 경우.

추가 정보

적용 대상