locked
Error - There is no row at position 0 RRS feed

  • Question

  • User1825646863 posted

    hi,

    i m new to asp.net. and i have to modify an existing project. the problem i m facing is - when i fill the registration form and click on submit button it shows error - System.IndexOutOfRangeException: There is no row at position 0.

    can anyone describe what could be the reason for this problem??? is it related to database empty? dataset empty? or validation error?

    thanks

    Thursday, September 21, 2006 1:00 AM

Answers

  • User-698857717 posted
    Ya, it seems to be some problem with your database..... may be there is no data in the database..... or you are not able to fetch the data in a proper way..... can you show me your code..?
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 21, 2006 1:14 AM

All replies

  • User-698857717 posted
    Ya, it seems to be some problem with your database..... may be there is no data in the database..... or you are not able to fetch the data in a proper way..... can you show me your code..?
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 21, 2006 1:14 AM
  • User1825646863 posted

    thanks for reply. here is error and code

    Error Message:

    System.IndexOutOfRangeException: There is no row at position 0. at System.Data.DataRowCollection.get_Item(Int32 index) at TLS.Security.BL.SecurityController.GetTLSEasyAgreementNPolicyText()

    Code -

    public string GetTLSEasyAgreementNPolicyText()
      {
       System.Collections.Specialized.NameValueCollection values = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationSettings.GetConfig( "appSettings" );
       try
       {    
        string url = values["SCTLSEasyAgreementNPolicy"];
        Security.DB.Security info = this.GetUserRegInfoFromState();
        ResourceGateway gateway = new ResourceGateway();
        DataSet ds = gateway.FindResourceByURL(url, "P");
        System.Byte []a =(System.Byte[])ds.Tables[0].Rows[0]["CONTENT"];
        if(((string)ds.Tables[0].Rows[0]["CONTENT_STATUS"])== "P")
        {
         return System.Text.Encoding.Default.GetString(a);
        }
        else
        {     
         return values["SCPageNotAccessibleMessage"];     
        }
       }
       catch(Exception e)
       {
        this.State["Exception"] = e.ToString();
        this.State.NavigateValue = "fail";  
       }   
       this.Navigate();

       return String.Empty;
      }

    Thursday, September 21, 2006 1:21 AM
  • User-698857717 posted

    sorry manoj,

    i can't help you. your code is in C# and i am not much familiar with C#. and most of the things are going above my head.... but its also saying IndexOutOfRange Exception....... may be there is something wrong about the array(System.Byte) you are using.....

    With Regards

    Thursday, September 21, 2006 2:08 AM
  • User2119691303 posted

    The problem is this line:

      if(((string)ds.Tables[0].Rows[0]["CONTENT_STATUS"])== "P")
      

    Basically the exception you are getting is saying that there isnt a row 0 in table 0 of the result of the the query.  The easiest way to get rid of this type of exception is to check that the required elements exist before trying to retrieve the data from them like this:

     

    if(ds.Tables[0].Rows.Count >0)

    {

       if(((string)ds.Tables[0].Rows[0]["CONTENT_STATUS"])== "P")
        {
         return System.Text.Encoding.Default.GetString(a);
        }
        else
        {     
         return values["SCPageNotAccessibleMessage"];     
        }  

    else

    {

        //There is no data so return a value to show this - maybe the same message as the else statement above.
     

    Thursday, September 21, 2006 5:11 AM
  • User375858556 posted

    This line is your problem:

     System.Byte []a =(System.Byte[])ds.Tables[0].Rows[0]["CONTENT"];

     ds.Tables[0] does not have any rows...so make sure it's being filled correctly.

     The poster that said   if(((string)ds.Tables[0].Rows[0]["CONTENT_STATUS"])== "P") is a problem is also correct - same problem...but the line above it is where the error is happening and fixing that error will take care of both of these.

     

    - Adam

     

    Thursday, September 21, 2006 10:55 AM
  • User375858556 posted

    This line is your problem:

     System.Byte []a =(System.Byte[])ds.Tables[0].Rows[0]["CONTENT"];

     ds.Tables[0] does not have any rows...so make sure it's being filled correctly.

     The poster that said   if(((string)ds.Tables[0].Rows[0]["CONTENT_STATUS"])== "P") is a problem is also correct - same problem...but the line above it is where the error is happening and fixing that error will take care of both of these.

     

    - Adam

     

    Thursday, September 21, 2006 10:55 AM
  • User854636040 posted

    it is always good to validate wether the dataset has data or is empty you can use something like this to cover all validations

     if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
    {
      //process data
    }
    else
    {
     // it is empty
    }

    hope this helps !

    Thursday, September 21, 2006 5:34 PM
  • User1825646863 posted
    thanks to all. i tried all solutions. but it is still showing the same error. i don't know what is going wrong?
    Friday, September 22, 2006 12:58 AM
  • User-1842880510 posted

    I don't know if you ever got an answer to your question.  I am experiencing the same issue in VB.Net.  I am checking the Rows.Count to verify it is greater than 0.  (In fact it is 38.  I saved the count and had it show up in the exeception message)  I thought it might be because that particular column of row 0 is DBNull.  All to no avail.  It seems as though The error is cropping due to some other problem for which there is no proper error message.  I hope someone can resolve this.

    Tuesday, August 28, 2007 11:44 PM
  • User-1766052905 posted

    You can use this to rectify this issue;

    set in ur dropdown list as  2+1 rows.

     

    Example:

    If u have 2 items in ddl u make it 2+1 items

    DDLvalue            DDLname

    0                         Select (show in ddl as default)

    1                         user

    2                        administrator

    so when u select the item from the ddl it always point out the row1.

     

    Wednesday, March 3, 2010 2:43 AM