AccessDataSource Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de AccessDataSource klasse.
Overloads
| Name | Description |
|---|---|
| AccessDataSource() |
Initialiseert een nieuw exemplaar van de AccessDataSource klasse. |
| AccessDataSource(String, String) |
Initialiseert een nieuw exemplaar van de AccessDataSource klasse met het opgegeven pad naar het gegevensbestand en de opdracht Selecteren . |
AccessDataSource()
Initialiseert een nieuw exemplaar van de AccessDataSource klasse.
public:
AccessDataSource();
public AccessDataSource();
Public Sub New ()
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de AccessDataSource constructor gebruikt om een nieuwe AccessDataSource gegevensbronbeheer te maken en een CheckBoxList-besturingselement te koppelen aan gegevens in een Microsoft Access-database.
<%@ 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>
Zie ook
Van toepassing op
AccessDataSource(String, String)
Initialiseert een nieuw exemplaar van de AccessDataSource klasse met het opgegeven pad naar het gegevensbestand en de opdracht Selecteren .
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)
Parameters
- dataFile
- String
De locatie van het Access .mdb-bestand. De locatie kan relatief zijn ten opzichte van de map van het huidige webformulier, een absoluut fysiek pad of een virtueel pad.
- selectCommand
- String
De SQL-query die wordt gebruikt om gegevens op te halen uit de Access-database. Als de SQL-query een geparameteriseerde SQL-tekenreeks is, voegt u objecten toe Parameter aan de SelectParameters verzameling.
Uitzonderingen
dataFile is null of een lege tekenreeks.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de AccessDataSource constructor gebruikt om een nieuwe AccessDataSource gegevensbronbeheer te maken en een CheckBoxList-besturingselement te koppelen aan gegevens in een Microsoft Access-database.
<%@ 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>