AccessDataSource 생성자

정의

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

오버로드

AccessDataSource()

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

AccessDataSource(String, String)

지정된 데이터 파일 경로와 Select 명령을 사용하여 AccessDataSource 클래스의 새 인스턴스를 초기화합니다.

AccessDataSource()

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

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

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 AccessDataSource 새 생성자 AccessDataSource 데이터 소스 제어 및 바인딩은 CheckBoxList Microsoft Access 데이터베이스의 데이터를 제어 합니다.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private void Page_Load(Object sender, EventArgs e) {

  // Create the AccessDataSource.
  AccessDataSource accessDS = new AccessDataSource();
  accessDS.SelectCommand = "SELECT SupplierID, CompanyName " +
                           " FROM Suppliers WHERE Country ='Germany'";
  accessDS.DataFile = "~/App_Data/Northwind.mdb";

  // Add the AccessDataSource to the Page.Controls collection.
  Page.Controls.Add(accessDS);

  // In programmatic scenarios, use the DataSource
  // property, not the DataSourceID property. The Select method
  // returns an IEnumerable list of data items.
  CheckBoxList1.DataSource = accessDS;

  // Explicitly call DataBind.
  CheckBoxList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:CheckBoxList
        id="CheckBoxList1"
        runat="server"
        DataTextField="CompanyName"
        DataValueField="SupplierID">
      </asp:CheckBoxList>

    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

  ' Create the AccessDataSource.
  Dim accessDS As New AccessDataSource()
  accessDS.SelectCommand = "SELECT SupplierID, CompanyName " & _
                           " FROM Suppliers WHERE Country ='Germany'"
  accessDS.DataFile = "~/App_Data/Northwind.mdb"

  ' Add the AccessDataSource to the Page.Controls collection.
  Page.Controls.Add(accessDS)

  ' In programmatic scenarios, use the DataSource
  ' property, not the DataSourceID property. The Select method
  ' returns an IEnumerable list of data items.
  CheckBoxList1.DataSource = accessDS

  ' Explicitly call DataBind.
  CheckBoxList1.DataBind()

End Sub 'Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:CheckBoxList
        id="CheckBoxList1"
        runat="server"
        DataTextField="CompanyName"
        DataValueField="SupplierID">
      </asp:CheckBoxList>

    </form>
  </body>
</html>

추가 정보

적용 대상

AccessDataSource(String, String)

지정된 데이터 파일 경로와 Select 명령을 사용하여 AccessDataSource 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

dataFile
String

Access .mdb 파일의 위치입니다. 이 위치는 현재 Web Form의 폴더에 대한 상대 경로, 실제 절대 경로 또는 가상 경로일 수 있습니다.

selectCommand
String

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

예외

dataFilenull 또는 빈 문자열인 경우

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 AccessDataSource 새 생성자 AccessDataSource 데이터 소스 제어 및 바인딩은 CheckBoxList Microsoft Access 데이터베이스의 데이터를 제어 합니다.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private void Page_Load(Object sender, EventArgs e) {

  // Create AccessDataSource
  AccessDataSource accessDS =
    new AccessDataSource("~/App_Data/Northwind.mdb",
                         "SELECT SupplierID, CompanyName " +
                         " FROM Suppliers WHERE Country ='Germany'");

  // Add the AccessDataSource to the Page.Controls collection
  Page.Controls.Add(accessDS);

  // In programmatic scenarios, use the DataSource
  // property, not the DataSourceID property. The Select method
  // returns an IEnumerable list of data items.
  CheckBoxList1.DataSource = accessDS;

  // Explicitly call DataBind
  CheckBoxList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:CheckBoxList
        id="CheckBoxList1"
        runat="server"
        DataTextField="CompanyName"
        DataValueField="SupplierID">
      </asp:CheckBoxList>

    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

  ' Create AccessDataSource
  Dim accessDS As New AccessDataSource("~/App_Data/Northwind.mdb", _
                                       "SELECT SupplierID, CompanyName " & _
                                      " FROM Suppliers WHERE Country ='Germany'")

  ' Add the AccessDataSource to the Page.Controls collection
  Page.Controls.Add(accessDS)

  ' In programmatic scenarios, use the DataSource
  ' property, not the DataSourceID property. The Select method
  ' returns an IEnumerable list of data items.
  CheckBoxList1.DataSource = accessDS

  ' Explicitly call DataBind
  CheckBoxList1.DataBind()

End Sub 'Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:CheckBoxList
        id="CheckBoxList1"
        runat="server"
        DataTextField="CompanyName"
        DataValueField="SupplierID">
      </asp:CheckBoxList>

    </form>
  </body>
</html>

추가 정보

적용 대상