Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:28:09+00:00 2026-06-15T03:28:09+00:00

i have this code that im getting error and, and cant understand why im

  • 0

i have this code that im getting error and, and cant understand why im getting the error. the code is as following: im using two arrays a string and a double(data values with their corresponding tinestamp). But for some reason im getting error that: index out of bounds error on this line:

     getSelectedItemsObj.arrayOfTimeStamp        = GetItemData(parameterName[counter], fromTime, toTime).arrayOfTimeStamp;

If i remove this line and only use arrayOfValue the code works fine, but i need both

………. Thanks for the fast replies, here is how GetItemData is set up

 public CustomDataType GetItemData(string parameterName, string fromTime, string toTime)
    {

        getWeatherItemObj = new CustomDataType();
        // get the parameter ID
        prameterID = GetParameterInfo(parameterName).ParameterID; 
        //get the nr of items to size value arrays
        tableSize = GetTableSize(parameterName, fromTime, toTime, prameterID);
        getWeatherItemObj.arrayOfValue      = new double[tableSize];            
        getWeatherItemObj.arrayOfTimeStamp  = new string[tableSize];
        counter = 0;
        try
        {
            using (conn = new SqlConnection(connectionString))// create and open a connection object
            {
                // 1. create a command object identifying the stored procedure
                 cmd = new SqlCommand("GetItemData", conn);
                // 2.Let the command object know we will execute a stored procedure
                cmd.CommandType = CommandType.StoredProcedure;
                // 3. add the 3 parameters to command, so the can be passed to the stored procedure                  
                cmd.Parameters.Add("@ParameterName", SqlDbType.VarChar).Value    = parameterName;
                cmd.Parameters.Add("@FromTime", SqlDbType.VarChar).Value                = fromTime;
                cmd.Parameters.Add("@ToTime", SqlDbType.VarChar).Value                  = toTime;
                //open connection
                conn.Open();
                // execute the command
                reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        getWeatherItemObj.arrayOfValue[counter]         = (double)reader["MeasurementValue"];
                        getWeatherItemObj.arrayOfTimeStamp[counter]     = reader["MeasurementDateTime"].ToString();                          
                        counter++;
                    }
                } 
                //close connection
                reader.Close();            
            }
        }
        catch (SqlException e)
        {
            Console.WriteLine("Connection failed");
            Console.WriteLine(e.Message);
            Thread.Sleep(5000);
        }           
        return getWeatherItemObj;
    }






 class CustomDataType
{
    public double[] arrayOfValue;
    public string[] arrayOfTimeStamp;

}

public CustomDataType GetSelectedtemsData(string[] parameterName, string fromTime, string toTime)
    {
        numberOfParameters = parameterName.Length;//Get the number of given parameters
        tableSize = 0;
        for (counter = 0; counter < numberOfParameters; counter++)
        {
            tableSize = tableSize + GetItemData(parameterName[counter], fromTime, toTime).arrayOfTimeStamp.Length;               
        }

        getSelectedItemsObj = new CustomDataType();

        getSelectedItemsObj.arrayOfValue        = new double[tableSize];
        getSelectedItemsObj.arrayOfTimeStamp    = new string[tableSize];
        for (counter = 0; counter < tableSize; counter++)
        { 
            getSelectedItemsObj.arrayOfValue            = GetItemData(parameterName[counter], fromTime, toTime).arrayOfValue;
            getSelectedItemsObj.arrayOfTimeStamp        = GetItemData(parameterName[counter], fromTime, toTime).arrayOfTimeStamp;

        }
        return getSelectedItemsObj;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:28:10+00:00Added an answer on June 15, 2026 at 3:28 am

    Please try the following:

    public CustomDataType GetSelectedtemsData(string[] parameterName, string fromTime, string toTime)
    {
        CustomDataType tempObj;     // *Rename this variable*
        List<double> valueList = new List<double>();
        List<string> timeStampList = new List<string>();
    
        for (counter = 0; counter < parameterName.Length; counter++)
        {
            tempObj = GetItemData(parameterName[counter], fromTime, toTime);
            valueList.AddRange(tempObj.arrayOfValue);
            timeStampList.AddRange(tempObj.arrayOfTimeStamp);
        }
    
        getSelectedItemsObj = new CustomDataType();
        getSelectedItemsObj.arrayOfValue = valueList.ToArray();
        getSelectedItemsObj.arrayOfTimeStamp = timeStampList.ToArray();
    
        return getSelectedItemsObj;
    }
    

    I was going to try it your way, but once I realized you were pulling each parameterName 3 times, and the second loop would need an inner loop (since you would need to iterate through each index in each GetItemData), and that my fix would have resulted in multiple copies of the same data anyways; I decided to rebuild the method using two List.

    If this does not solve your issue then I will need the complete error message, the stack trace from the error message, and the code of the top most method on the error stack.

    Note: There are a number of additional optimizations which may help you like:

    • You may also want to update GetItemData to also use List instead of arrays so you can skip the tableSize = GetTableSize(parameterName, fromTime, toTime, prameterID); line.
    • You may want to change CustomDataType so arrayOfValue and arrayOfTimeStamp are not arrays. Then, instead of passing a CustomDataType out you could pass a CustomDataType[] or even List<CustomDataType>.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that reads from XML file. It gets five strings (groupId,
I have this code that suppose to place the marker by the latlng public
I have this code that where I would normally use one line: if (tableView
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.