Solved

IDataReader System.IndexOutOfRangeException on Class File Object

Posted on 2008-10-24
3
569 Views
Last Modified: 2012-05-05
Hi,

I'm building a class file, and I am getting an System.IndexOutOfRangeException: when I get past the third property.  I have no idea why!

I've attached my business object


The error is raised on the line that reads: _DataTitle = reader["DataTitle"].ToString(); in the public Data999(IDataReader reader) section


using System;

using System.Data;

using System.Configuration;

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;
 

/// <summary>

/// Summary description for Data999

/// </summary>

/// 
 

public class Data999

{

    private string _DataTitle;

    public string DataTitle

    {

        get { return _DataTitle; }

        set { _DataTitle = value; }

    }
 

    private string _Forename;

    public string Forename

    {

        get { return _Forename; }

        set { _Forename = value; }

    }
 

    private string _Surname;

    public string Surname

    {

        get { return _Surname; }

        set { _Surname = value; }

    }
 

    private string _Honours;

    public string Honours

    {

        get { return _Honours; }

        set { _Honours = value; }

    }
 

    private string _BusinessPrefix;

    public string BusinessPrefix

    {

        get { return _BusinessPrefix; }

        set { _BusinessPrefix = value; }

    }
 

    private string _Premises;

    public string Premises

    {

        get { return _Premises; }

        set { _Premises = value; }

    }
 

    private string _Throughfare;

    public string Throughfare

    {

        get { return _Throughfare; }

        set { _Throughfare = value; }

    }
 

    private string _Locality;

    public string Locality

    {

        get { return _Locality; }

        set { _Locality = value; }

    }
 

    private string _Postcode;

    public string Postcode

    {

        get { return _Postcode; }

        set { _Postcode = value; }

    }
 

    private string _addedBy;

    public string addedBy

    {

        get { return _addedBy; }

        set { _addedBy = value; }

    }
 

    private string _TelephoneNumber;

    public string TelephoneNumber

    {

        get { return _TelephoneNumber; }

        set { _TelephoneNumber = value; }

    }
 

    private string _Deleted;

    public string Deleted

    {

        get { return _Deleted; }

        set { _Deleted = value; }

    }
 
 
 

	public Data999(IDataReader reader)

	{

        _addedBy = reader["addedBy"].ToString();

        _TelephoneNumber = reader["TelephoneNumber"].ToString();

        _Deleted = reader["Deleted"].ToString();

        _DataTitle = reader["DataTitle"].ToString();

        _Forename = reader["Forename"].ToString();

        _Surname = reader["Surname"].ToString();

        _Honours = reader["Honours"].ToString();

        _BusinessPrefix = reader["BusinessPrefix"].ToString();

        _Premises = reader["Premises"].ToString();

        _Throughfare = reader["Throughfare"].ToString();

        _Locality = reader["Locality"].ToString();

        _Postcode = reader["Postcode"].ToString();
 

	}

}
 
 
 

================

EXCEPTION DETAILS

================
 

Exception Details: System.IndexOutOfRangeException: DataTitle
 

Source File: c:\Inetpub\wwwroot\eff999\App_code\Data999.cs    Line: 109 
 

Source Error: 
 
 

Line 107:        _TelephoneNumber = reader["TelephoneNumber"].ToString();

Line 108:        _Deleted = reader["Deleted"].ToString();

Line 109:        _DataTitle = reader["DataTitle"].ToString();

Line 110:        _Forename = reader["Forename"].ToString();

Line 111:        _Surname = reader["Surname"].ToString();

Open in new window

0
Comment
Question by:krapvag
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Werrock
Comment Utility
Could you add the business object once more. I cannot see it.
0
 
LVL 1

Author Comment

by:krapvag
Comment Utility
using System;
using System.Data;
using System.Configuration;
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;

/// <summary>
/// Summary description for Data999
/// </summary>
///

public class Data999
{
    private string _DataTitle;
    public string DataTitle
    {
        get { return _DataTitle; }
        set { _DataTitle = value; }
    }

    private string _Forename;
    public string Forename
    {
        get { return _Forename; }
        set { _Forename = value; }
    }

    private string _Surname;
    public string Surname
    {
        get { return _Surname; }
        set { _Surname = value; }
    }

    private string _Honours;
    public string Honours
    {
        get { return _Honours; }
        set { _Honours = value; }
    }

    private string _BusinessPrefix;
    public string BusinessPrefix
    {
        get { return _BusinessPrefix; }
        set { _BusinessPrefix = value; }
    }

    private string _Premises;
    public string Premises
    {
        get { return _Premises; }
        set { _Premises = value; }
    }

    private string _Throughfare;
    public string Throughfare
    {
        get { return _Throughfare; }
        set { _Throughfare = value; }
    }

    private string _Locality;
    public string Locality
    {
        get { return _Locality; }
        set { _Locality = value; }
    }

    private string _Postcode;
    public string Postcode
    {
        get { return _Postcode; }
        set { _Postcode = value; }
    }

    private string _addedBy;
    public string addedBy
    {
        get { return _addedBy; }
        set { _addedBy = value; }
    }

    private string _TelephoneNumber;
    public string TelephoneNumber
    {
        get { return _TelephoneNumber; }
        set { _TelephoneNumber = value; }
    }

    private string _Deleted;
    public string Deleted
    {
        get { return _Deleted; }
        set { _Deleted = value; }
    }



      public Data999(IDataReader reader)
      {
        _addedBy = reader["addedBy"].ToString();
        _TelephoneNumber = reader["TelephoneNumber"].ToString();
        _Deleted = reader["Deleted"].ToString();
        _DataTitle = reader["DataTitle"].ToString();
        _Forename = reader["Forename"].ToString();
        _Surname = reader["Surname"].ToString();
        _Honours = reader["Honours"].ToString();
        _BusinessPrefix = reader["BusinessPrefix"].ToString();
        _Premises = reader["Premises"].ToString();
        _Throughfare = reader["Throughfare"].ToString();
        _Locality = reader["Locality"].ToString();
        _Postcode = reader["Postcode"].ToString();

      }
}
0
 
LVL 6

Accepted Solution

by:
Werrock earned 125 total points
Comment Utility
Yeah, its probably since the column does not exists. This has been addressed before at:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23257624.html

So please confirm that the column exists and try to check it before calling or handle exceptions by catching them in the constructor.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Change to event 1 72
Problem with SqlConnection 5 109
Windows Service with UDP 2 26
Throws error on Decrypting String c# code 3 26
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now