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.
|