如何从三维数组中的表中获取数据? [英] How do i get my data from table in 3 dimensional array?

查看:438
本文介绍了如何从三维数组中的表中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
            }

        }
    }











由于我有22行数据,我得到了索引无限制的错误。&在这个代码我只得到coulmns.how我可以在数组中获取数据??






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??

推荐答案

在这一行
arraylist[i, i, i, j] = dt.Columns[j].ToString();



如果 i 大于4将抛出异常。那是因为你已经将数组声明为


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];

?我不能说出确切的答案,因为我不知道你要做什么。



另外,通过查看方法的名称(getDailyAvgRatingByCompanyId),我认为使用数据库查询可能比使用代码更容易。



或许这可以通过Linq完成(如果你是使用C#3.5或更新版本?

? 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)?


这篇关于如何从三维数组中的表中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆