将数据从表移动到数组 [英] Move Data from table to Array

查看:82
本文介绍了将数据从表移动到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种快速的方法将数据从DataTable移动到双数组,还是我必须遍历每个记录和列?


我有五个表,我需要合并这些表是列式的,每个表都有相同数量的记录,但可能有不同的列数。


所以我需要第一个记录表格table1和table2以及table3和table4和table5在我的合并数组或表中记录1。

第二个记录表格table1和table2以及table3和table4以及table5在我的合并数组或表格中的记录2中。

....

....

....


最终的数组或表可能有2000行和7000列。


谢谢

彼得

解决方案

< BLOCKQUOTE>>所以我需要第一个记录表格table1和table2以及table3和table4以及table5在我的合并数组或表中的记录1中。

第二个记录表格table1和table2以及table3和table4以及table5是在我的合并数组或表中的记录2中。
...




您的数据来自哪里?


当你获取

数据时,你不能只在SELECT子句中指定它,例如:


SELECT * FROM TABLE1,TABLE2,TABLE3 ,TABLE4,TABLE5

WHERE TABLE1.KEY = TABLE2.KEY和TABLE2.KEY = TABLE3.KEY和......


或类似的东西?


如果没有,我会建议你在内存中填充你的b / b
DataTable / Array的时间可能会比
更苍白
首先将数据从数据库中取出所需的时间。

唯一可以确定的方法是编写简单的算法

(循环在循环中)然后通过分析器运行程序

查看它花费时间的地方。


嗨彼得,


就像布鲁斯说的那样,当您从数据中选择时,最好进行合并

来源。如果你真的需要将它们移动到一个数组,你必须在DataTable中的每一行经过

。 DataRow有一个ItemArray属性,

返回一个对象数组,其中包含每列的值。


HTH。


Kevin Yu

=======

此帖子已提供按现状没有保证,也没有赋予

权利。


" Kevin Yu [MSFT]" <,V - **** @ online.microsoft.com>在消息中写道

新闻:EL ************** @ TK2MSFTNGXA02.phx.gbl ...

嗨彼得,通过DataTable中的每一行。 DataRow有一个ItemArray属性,它返回一个包含每列值的对象数组。

HTH。

Kevin Yu
== =====
此帖子已提供按原样没有保证,也没有授予
权利。




数据来自Excel电子表格

每个工作表内的电子表格可以有不同数量的列

,列名可以是任何东西,所以基本上我必须将每个

电子表格合并到主电子表格中,每个工作表中的每个Row1都会在主工作表的Row1中是
。但是我不能使用Excel,因为我可能

最终会有7000列。


不知怎的,我必须将所有工作表数据移入一个数组

非常快。


Is there a fast way to move data from DataTable into double array, or do I have to spin through every record and column?

I have five tables and I need to merge these tables column wise, each table will have to same amount of records but might have different amount of columns.

So I need the first record form table1 and table2 and table3 and table4 and table5 to be in record 1 in my merged array or table.
Second record form table1 and table2 and table3 and table4 and table5 to be in record 2 in my merged array or table.
....
....
....

the final array or table might have 2000 rows and 7000 columns.

Thanks
Peter

解决方案

> So I need the first record form table1 and table2 and table3 and table4 and table5 to be in record 1 in my merged array or table.

Second record form table1 and table2 and table3 and table4 and table5 to be in record 2 in my merged array or table.
...



Where is your data coming from?

Can''t you just specify this on the SELECT clause when you fetch the
data, e.g.:

SELECT * FROM TABLE1, TABLE2, TABLE3, TABLE4, TABLE5
WHERE TABLE1.KEY = TABLE2.KEY AND TABLE2.KEY = TABLE3.KEY AND ...

or something like that?

If not, I would propose that the time it takes you to populate your
DataTable / Array in memory will probably pale in comparison to the
time it takes to get the stuff out of the database in the first place.
The only way to know for sure is to write the simple-minded algorithm
(loops within loops) and then run your program through a profiler to
see where it''s spending its time.


Hi Peter,

Like Bruce said, it''s better to do the merge when you select from the data
source. If you really need to move them to an array, you have to go through
each row in the DataTable. The DataRow has an ItemArray property which
returns an array of object that contains the values for each column.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:EL**************@TK2MSFTNGXA02.phx.gbl...

Hi Peter,

Like Bruce said, it''s better to do the merge when you select from the data
source. If you really need to move them to an array, you have to go
through
each row in the DataTable. The DataRow has an ItemArray property which
returns an array of object that contains the values for each column.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."



Data is coming from a Excel spreadsheet
each worksheet within the spreadsheet can have variable number of columns
and the column names can be anything, so basically I have to merge each
spreadsheet to the main spreadsheet, each Row1 from each worksheet will be
in the Row1 of the main worksheet. But I can not use Excel because I might
end up with up to 7000 columns.

Somehow I have to get the all of the worksheets data moved into an array
very fast.


这篇关于将数据从表移动到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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