Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void getDailyAvgRatingByCompanyId()
    {
        List<int[]> rowList = new List<int[]>();
        SqlCommand cmd = new SqlCommand("select t.ApplicationTemplateRowId,t.MomMessage,t.VendorErrorCode,t.VendorMessage from APPLICATIONTEMPLATE t", con);
       
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
      
        string[, , ,] arraylist = new string[dt.Columns.Count, 4, 4, 4];
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                arraylist[i, i, i, j] = dt.Columns[j].ToString();
            }

        }
    }





I got error that index is unbounded as i have 22 rows of data..& in this code i got only coulmns.how can i get data in array??
Posted
Updated 21-Mar-13 21:01pm
v2
Comments
Matt T Heffron 22-Mar-13 17:13pm    
Why is the Rank of this array 4?
You are using i for three of the 4 indices.
It could be replaced by a 2 dimensional array, and then initialize with
string [,] arraylist = new string[dt.Rows.Count, dt.Columns.count];
and just assign into:
arraylist[i, j] = ...

1 solution

On this line
arraylist[i, i, i, j] = dt.Columns[j].ToString();

if i is greater than 4 it will throw the exception. That's because you have declared the array as
new string[dt.Columns.Count, 4, 4, 4];


Maybe it should be
new string[dt.Columns.Count, dt.Rows.Count, 4, 4];
? I can't tell the exact answer because I don't know what you're trying to do.

Also, by looking the name of your method (getDailyAvgRatingByCompanyId), I think this might be easier to do with a database query than with code.

Or maybe this could be done with Linq (if you're using C# 3.5 or newer)?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900