• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Index out of range

I am filtering through an index
                if ((result.Title == ds.Tables[0].Rows[0].ItemArray[6].ToString()) == true)
                {
                    foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                    {
                        //result.Title = ds.Tables[0].Rows[0].ItemArray[6].ToString();
                        result.Title = dr.ItemArray[6].ToString();
                    }
                    results.Add(result);
                }
                else
                {
                }
I can out figure out how to write my if statement  so that it doesn't show a file if is not in the database based on my query.
the app does give me the message: There is no row at position 0. but dies with this message
0
MoniMatthews
Asked:
MoniMatthews
  • 4
1 Solution
 
97WideGlideCommented:
if ((result.Title = ds.Tables[0].Rows[0].ItemArray[6].ToString()) == true)
0
 
MoniMatthewsAuthor Commented:
that's what i have.
0
 
MoniMatthewsAuthor Commented:
For anyone that has this problem.
My answer was to change my if statement
if(strSql.Length == 0)
{
then code
}
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>the app does give me the message: There is no row at position 0
that means that the ds.tables[0] has no rows.

apart from that:
if ((result.Title == ds.Tables[0].Rows[0].ItemArray[6].ToString()) == true)
should be:
if ( result.Title == ds.Tables[0].Rows[0].ItemArray[6].ToString() )
0
 
MoniMatthewsAuthor Commented:
I found the answer that best fits my code.
0
 
MoniMatthewsAuthor Commented:
While I figured out how to resolve my issue before your post. Your response is correct.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

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