Results 1 to 2 of 2

Thread: Selection box connected to a database

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question Selection box connected to a database

    How can I generate the content of a selection box from a database e.g an Access database?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    here's one way:
    Code:
    <%@ Import Namespace = "System.Data" %>
    <%@ Import Namespace = "System.Data.OleDb" %>
    <script runat="server" language="vb">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    	If Not Page.IsPostBack Then
    		bindAuthors()
    	End If
    End Sub
    Protected Sub bindAuthors()
    	Dim mdbPath As String = "D:\AccessData\Biblio2002.mdb"
    	Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath
    	Dim cn As OleDbConnection = New OleDbConnection(connString)
    	Dim cmdText As String = "Select au_id As AuthorId, Author From Authors Order By Author"
    	Dim cmd as OleDbCommand = New OleDbCommand(cmdText, cn)
    	cmd.Connection.Open()
    	Authors.DataSource = cmd.ExecuteReader()
    	Authors.DataValueField = "AuthorId"
    	Authors.DataTextField = "Author"
    	Authors.DataBind()
    	cmd.Connection.Close()
    End Sub 
    </script>
    <html>
      <head>
        <title>DataBoundCombo</title>
      </head>
      <body>
    
        <form id="DataBoundCombo" method="post" runat="server">
    		<asp:DropDownList
    			Runat="server"
    			ID="Authors"/>	
        </form>
    
      </body>
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width