Popolare una DropDownList leggendo i dati da Access
<%@ Page language="VB" Debug="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<HTML>
<script language="vbscript" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & _
Server.MapPath("database/utenti.mdb"))
Dim myCmd As OleDbCommand = New OleDbCommand("select nome, cognome from utenti", myConn)
If Not Page.IsPostBack then
Try
myConn.Open()
myDropDownList.DataSource = myCmd.ExecuteReader()
myDropDownList.DataValueField="nome"
myDropDownList.DataTextField="cognome"
myDropDownList.DataBind()
Finally
myConn.Close()
End Try
End If
End Sub
</script>
<body>
<form Name="Form1" Runat="server">
<asp:DropDownList ID="myDropDownList" Runat="server"></asp:DropDownList>
</form>
</body>
</html>