Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2003, 04:57 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Connection to a Access database

Guys,

I am trying to populate a list box using the following code. The code compiles ok but the listbox does not populate! Any ideas??

Easy

Adz

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>

<html>
  <head>
    <title>using a Listbox</title>
  </head>
  <body>
    <h3>Using a Listbox</h3>
    <form runat="server">
      <asp:ListBox id="IbxEmployees" runat="server"
       AutoPostBack="True"
       Rows="5"
       OnSelectedIndexChanged="subListChange" />
    </form>
  </body>
</html>

<script language="C#" runat="server">
private void Load_Page(object sender, System.EventArgs e)
{
  if (!IsPostBack)
  {
        String strConnection = "Provider=Microsoft.Jet.OleDb.4.0; data source=C:\\test\\Northwind.mdb;";
    OleDbConnection objConnection = new OleDbConnection(strConnection);

    String strSQLforListBox = "SELECT LastName, EmployeeID " + "FROM Employees ORDER BY LastName";
    OleDbCommand objCommand = new OleDbCommand(strSQLforListBox, objConnection);

    objConnection.Open();
    IbxEmployees.DataSource = objCommand.ExecuteReader();
    IbxEmployees.DataTextField = "LastName";
        IbxEmployees.DataValueField = "EmployeeID";
        IbxEmployees.DataBind();
    objConnection.Close();
  }
}

__________________
Adz - Learning The J2EE Ways.
 
Old October 12th, 2003, 05:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is it on purpose that you have called the method Load_Page and not Page_Load...?!

Jacob.

 
Old October 13th, 2003, 06:35 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Jacob,

you star, I feel like such a plum. Guess thats what happens when you are a beginner.

Cheers mate

Adz






Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection to Access Database in .Net KarthikR BOOK: ASP.NET Website Programming Problem-Design-Solution 1 January 16th, 2007 11:56 AM
How to make a connection with access database arshad mahmood Classic ASP Professional 1 April 18th, 2006 03:53 AM
access database connection problem shaileshk ADO.NET 6 July 5th, 2005 03:30 AM
Connection DataGrid to Access database Rado C# 1 April 25th, 2005 04:59 AM
Access Database connection widad Classic ASP Databases 3 November 5th, 2004 05:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.