AccessDataSource Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe AccessDataSource.
Surcharges
| Nom | Description |
|---|---|
| AccessDataSource() |
Initialise une nouvelle instance de la classe AccessDataSource. |
| AccessDataSource(String, String) |
Initialise une nouvelle instance de la classe AccessDataSource avec le chemin d’accès du fichier de données spécifié et sélectionner commande. |
AccessDataSource()
Initialise une nouvelle instance de la classe AccessDataSource.
public:
AccessDataSource();
public AccessDataSource();
Public Sub New ()
Exemples
L’exemple de code suivant montre comment utiliser le constructeur AccessDataSource pour créer un contrôle de source de données AccessDataSource et lier un contrôle CheckBoxList aux données d’une base de données 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>
Voir aussi
S’applique à
AccessDataSource(String, String)
Initialise une nouvelle instance de la classe AccessDataSource avec le chemin d’accès du fichier de données spécifié et sélectionner commande.
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)
Paramètres
- dataFile
- String
Emplacement du fichier .mdb Access. L’emplacement peut être relatif au dossier du formulaire Web actuel, à un chemin physique absolu ou à un chemin d’accès virtuel.
- selectCommand
- String
Requête SQL utilisée pour récupérer des données de la base de données Access. Si la requête SQL est une chaîne SQL paramétrable, ajoutez des Parameter objets à la SelectParameters collection.
Exceptions
dataFile est null ou une chaîne vide.
Exemples
L’exemple de code suivant montre comment utiliser le constructeur AccessDataSource pour créer un contrôle de source de données AccessDataSource et lier un contrôle CheckBoxList aux données d’une base de données 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>