473,670 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Move Data from table to Array

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

Nov 23 '05 #1
14 3588
> 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.

Nov 24 '05 #2
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."

Nov 24 '05 #3
"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:EL******** ******@TK2MSFTN GXA02.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.
Nov 24 '05 #4
> 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.


Well, everything is relative. In your case, I suspect that getting the
data out of the existing spreadsheets and writing it to wherever it has
to go will be (relatively) much slower than your merge operation.

The only way to know for sure is to take a shot at writing the merge
and, as I said, run your program under a profiler to see where it
spends most of its time. If the merge turns out to be a bottleneck,
then tune it, but I suspect that it won't be.

Nov 24 '05 #5

"Bruce Wood" <br*******@cana da.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
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.


Well, everything is relative. In your case, I suspect that getting the
data out of the existing spreadsheets and writing it to wherever it has
to go will be (relatively) much slower than your merge operation.

The only way to know for sure is to take a shot at writing the merge
and, as I said, run your program under a profiler to see where it
spends most of its time. If the merge turns out to be a bottleneck,
then tune it, but I suspect that it won't be.

Retreiving data from the Excel spreadsheet is relatively very fast, but
merging data into the array takes abut 10 minutes, compared to about 10
secods to retreive the data from the spreadsheet.

Here's my merge code.

for(int n = 0; i < importData.Coun t; n++)
{
mergedTable = (DataTable)impo rtData.Item[n];

for(int i = 1; i < maxRecords; i++)
{
col = holdCol;
for(int c = 1; c < mergedTable.Col umns.Count - 1; i++)
{
val = Convert.ToDoubl e(mergedTable.R ows[i][c]);
dataArray[i - 1, col] = val;
col++; // next column
}
}
}

So I need code that will move data from a table into an array very fast.
Nov 26 '05 #6
Hi Peter,

From the code, I can see that you're combining all the records in the
DataTables like the following:

data from DataTable1
data from DataTable2
data from DataTable3
........

In this case, if the schema of the tables are the same, when filling the
DataTable, you can simply use three DataAdapters to fill the same
DataTable. For example, filling it 3 times, like

DA1.Fill(dt);
DA2.Fill(dt);
DA3.Fill(dt);

will put data from 3 tables to the same DataTable.

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

Nov 28 '05 #7
Unfortunately the schema is different for each table, number of columns and
column names are different and on top of if the Master table will contain
only numbers, but the sheets might contain text columns which I have to
remove.
(Data comes from a spreadsheet supplied by a user)

So I think I need a routine that can move data from DataTable to an array
very fast.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:l%******** ********@TK2MSF TNGXA02.phx.gbl ...
Hi Peter,

From the code, I can see that you're combining all the records in the
DataTables like the following:

data from DataTable1
data from DataTable2
data from DataTable3
.......

In this case, if the schema of the tables are the same, when filling the
DataTable, you can simply use three DataAdapters to fill the same
DataTable. For example, filling it 3 times, like

DA1.Fill(dt);
DA2.Fill(dt);
DA3.Fill(dt);

will put data from 3 tables to the same DataTable.

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

Nov 28 '05 #8
The only thing I see in your code that would account for the 10 minutes
is the Convert.ToDoubl e() call. In what form are you getting the data
from the Excel spreadsheets?

Nov 28 '05 #9

"Bruce Wood" <br*******@cana da.com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
The only thing I see in your code that would account for the 10 minutes
is the Convert.ToDoubl e() call. In what form are you getting the data
from the Excel spreadsheets?


Here's sample data (delimited by spaces)

7/1/04 0:00 80 80.4143219 41.76826859 3620 85.99505615 4.173601627 722.7902832 674.1519775
7/1/04 1:00 80 80.41130066 41.76562119 3619.800049 85.99694824 4.63732338 777.8297119 730.9456177
7/1/04 2:00 80 79.91899872 41.76296997 3620 85.99486542 4.051301479 724.458313 654.1055908
7/1/04 3:00 80 80.48442078 41.76031876 3619.857178 85.99700165 4.282075405 720.6036987 700.1008301
7/1/04 4:00 80 80.36474609 41.75767136 3620 85.99711609 4.218424797 724.3544312 676.8447876
7/1/04 5:00 80 80.23025513 41.75502014 3620 85.99019623 4.297987461 723.5835571 691.6959839
7/1/04 6:00 80 80.43131256 41.75236893 3620 85.98691559 4.190071583 721.6431885 673.8577881

Nov 29 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3092
by: tshad | last post by:
Is there a way to move a row in a Datalist up or down without having to re-read the data? I have a datalist which has embedded Datagrids in it. I want to allow the user to move a row up or down by just pushing a button and have the page post back with the row moved without actually re-reading the data from the database? Thanks,
35
3016
by: Frederick Gotham | last post by:
(Before I begin, please don't suggest to me to use "std::vector" rather than actual arrays.) I understand that an object can have resources (e.g. dynamically allocated memory), and so we have to copy an object properly via copy- construction rather than using memcpy. However, is it okay to move an object manually (i.e. by using memcpy or memmove)?
33
2310
by: Frederick Gotham | last post by:
(My dialect of English seems to puzzle people at times, so I'll first clarify a few terms which I use in the following post:) (1) By "domestic", I mean "ordinary, run-of-the-mill, not extraordinary or strange". (2) By "willy-nilly", I mean something along the lines of "haphazardly", but without any sense of recklessness (i.e. gleefully doing something without expecting any sort of negative effect, even though there may in fact be a...
3
1881
by: Eric | last post by:
When i run my query it transfer last 4 digits of account number from one table to another and its wrong. There are two tables one i use for parsing. Second thru query i use to move data from temp table to actual table with some little changes in temp table. I use the same code in two different databases One database works fine and another database wont move the account number with 9 digit size. Difference is only the structre of text files...
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8896
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.