SqlDataSource 생성자

정의

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

오버로드

Name Description
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 만드는 방법을 보여 줍니다. 이 예제에서는 컨트롤이 Web Forms 페이지가 아니라 비즈니스 개체가 데이터베이스와 상호 작용하는 간단한 방법으로 중간 계층 개체를 구현하는 데 사용되고 있다는 SqlDataSource 사실이 특이합니다. 이 예제에서는 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을 사용하므로 사용되는 현재 ADO.NET 공급자에 따라 구문이 달라집니다. 이 구문 selectCommand 은 속성으로 ProviderName 식별됩니다. SQL 문자열이 매개 변수가 있는 쿼리 또는 명령인 경우 매개 변수의 자리 표시자도 사용 중인 ADO.NET 공급자에 따라 달라집니다. 예를 들어 공급자가 클래스의 System.Data.SqlClient기본 공급자 SqlDataSource 인 경우 매개 변수의 자리 표시자는 다음과 같습니다 '@parameterName'. 그러나 공급자가 또는 매개 변수로 System.Data.OdbcSystem.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.OdbcSystem.Data.OleDb설정된 경우 매개 변수의 자리 표시자는 .입니다 '?'. 매개 변수가 있는 SQL 쿼리 및 명령에 대한 자세한 내용은 SqlDataSource 컨트롤에서 매개 변수 사용을 참조하세요.

데이터 원본이 저장 프로시저를 지원하는 경우 이 속성은 SelectCommand SQL 문자열 또는 저장 프로시저의 이름이 될 수 있습니다.

추가 정보

적용 대상