Hello,

I am working on a web application that basically displays a phone directory of a certain organizational structure.

I am using C# and using the dataReader object. I don't want to use any databound controls. I simply want to display the fields and add conditional looping as desired.

The problem is, when i run the *.aspx page in the browser. The page doesn't recognize my dataReader object created and i receive the following error: The name 'dr_1' does not exist in the current context

Thank you in advance for the help!
Abdul

The 2 files and their code are as follows:

1. the web file default.aspx
Code:
<%@ Page Language="C#" MasterPageFile="~/other/contact/contact.master" AutoEventWireup="true" CodeFile="default3.aspx.cs" Inherits="other_contact_default3" Title="Untitled Page" %>
  
<asp:Content ID="Content3" ContentPlaceHolderID="mainContent" Runat="Server">
            <table border="0" width="100%" cellspacing="0">
  
            <% while( dr_1.Read()){ %>
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text='<% dr_1["name"].toString(); %>'></asp:Label>
                </td>
                <td>
                    <asp:Label ID="Label2" runat="server" Text='<% dr_1["office_phone"].toString();%>'></asp:Label>
                </td>
            </tr>
            <% } %>
  
            </table>
</asp:Content>
2. the code-behind file (default.aspx.cs):
Code:
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
  
public partial class other_contact_default : System.Web.UI.Page
{
  
    public void Page_Load(object sender, EventArgs e)
    {
    OleDbConnection conn;
     OleDbCommand comm;
     OleDbDataReader dr_1;
   
        conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=web_test/contacts.mdb;Persist Security Info=False");
        comm = new OleDbCommand("SELECT name, title, office_phone, note, network_id, org_code FROM EMPLOYEE WHERE (org_code = '400') ORDER BY sort_order", conn);
        conn.Open();
        dr_1 = comm.ExecuteReader();
  
conn.Close();
} }