# Help on using ASP.NET dataReader object in its abstract form!

**URL:** <https://forum.kirupa.com/t/help-on-using-asp-net-datareader-object-in-its-abstract-form/249604>\
**Category:** programming\
**Created:** [January 20, 2008, 7:16pm UTC](https://forum.kirupa.com/t/help-on-using-asp-net-datareader-object-in-its-abstract-form/249604 "2008-01-20T19:16:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdulmohsen](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abdulmohsen](https://forum.kirupa.com/u/abdulmohsen)\
**Post date:** [January 20, 2008, 7:16pm UTC](https://forum.kirupa.com/t/help-on-using-asp-net-datareader-object-in-its-abstract-form/249604/1 "2008-01-20T19:16:55Z")

</div>

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:

[INDENT] **1. the web file default.aspx**  
[/INDENT] [INDENT]

```auto

<%@ 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>
  

```

[/INDENT] [INDENT]\*\*2. the code-behind file (default.aspx.cs):  
\*\*[/INDENT] [INDENT]

```auto

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();
  [INDENT]conn.Close();
  [/INDENT] }
  
        
  
}
  

```

[/INDENT]
