[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

ASP.NET

           DataView db = (DataView)this.PartDescriptionCheck.Select(DataSourceSelectArguments.Empty);

            if ((db.Sort == null))
            {
                this.txtPartNumber.Text = "Hel";
                this.txtPartDescription.Text = null;
            }
            else
            {
                if (System.IndexOutOfRangeException <= 0)
                {
                }
                else
                {

                    this.txtPartDescription.Text = (String)db[0]["Description"];
                }
            }

I want to beable to capture The IndexOutOfRangeException before i set txtpartdescription = db[0]["Description"]

Any Ideas this in the Visual Studio .Net 2005 using c# to make a .aspx page

Thanks,
0
DRSLT
Asked:
DRSLT
3 Solutions
 
WelkinMazeCommented:
Hi,
Something like this I think

    Try
          ........
     Catch RangeEx As IndexOutOfRangeException
          Throw New Exception("Specified data was not found.")
     End Try
0
 
gazzzzzzerCommented:
//if you are trying to catch this exception when you attempt to access the db[0]["Description"] then use this solution

DataView db = (DataView)This.PartDescriptionCheck.Select(SataSourceSelectArguments.Empty);
            if ((db.Sort == null))
            {
                this.txtPartNumber.Text = "Hel";
                this.txtPartDescription.Text = null;
            }
            else
            {
                try
                {
                    this.txtPartDescription.Text = (String)db[0]["Description"];
                }
                catch (System.IndexOutOfRangeException ex)
                {
                        //CODE HERE TO HANDLE EXCEPTION
                }

            }
0
 
nayernaguibCommented:
Instead of catching the exception, you can do this check before trying to retrieve data from the DataView:

                if (db.Count > 0)
                {
                    this.txtPartDescription.Text = (String)db[0]["Description"];
                }

_______________

  Nayer Naguib
0
 
DRSLTAuthor Commented:
Thanks!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now