Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

DropDownList and Access - << C# VERSION >>


Populate a DropDownList reading data from 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>



Download Code...


Print Page


 








Page top

risorse per webmaster