473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Datatable conversion to an array

Hi

Is there any command to transfer the contents of a datatable to an array.
What I'm looking for is sort of a bulk process, not an iteration with a loop
based on a field by field or row by row process.

Regards
RMS
Nov 20 '05 #1
9 17673
Hi Rui,

What would you like your array to contain? Are you after a multi-dimensional array of Objects? Or a single-dimensional
array of Somethings?

This is what the DataTable would be asking if it could. Given that it can't anticipate or ask, it offers a collection
of Rows.

What did you have in mind?

Regards,
Fergus


Nov 20 '05 #2
"Rui Sampainho" <rs********@hotmail.com> schrieb

Is there any command to transfer the contents of a datatable to an
array. What I'm looking for is sort of a bulk process, not an
iteration with a loop based on a field by field or row by row
process.


Untested:
A DataTable implements the interface ICollection. The interface has a CopyTo
method.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #3
"Armin Zingler" <az*******@freenet.de> schrieb
Untested:
A DataTable implements the interface ICollection. The interface has a
CopyTo method.


Correction:
DataTable.Rows returns a System.Data.DataRowCollection that implements
ICollection.

Sorry.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #4
* "Rui Sampainho" <rs********@hotmail.com> scripsit:
Is there any command to transfer the contents of a datatable to an array.


Which part of the datatable do you want to store in an array?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #5
Hi Fergus!

I need to export the contents of a table to an Excel Spreadsheet. This table
has about 3000 rows.
I already have a very fast one-step process for transfering all of an array
content to excel (therefore the array has 2 dimensions - one for rows and
another for columns, so what I believe I need is a multi-dimensional array
of somethings - like strings).

The alternative I have in hands is to either loop through the items (or
maybe rows) of the datatable exporting them one-by-one, or looping through
the contents of the datatable and assigning the values to the array.
Whichever case makes the process a bit too slow and inefficient.

For example, the .lines property of a multi-lined string automatically
creates a 1 dimension array with all the lines of the string.

I guess what I'm looking for a similar process applied to the datatable case
(with lines and columns)

Thanks again

What I have in mind is transfering the actual datatable contents to an excel
spreadsheet.

"Fergus Cooney" <fi****@post.com> escreveu na mensagem
news:OM**************@TK2MSFTNGP10.phx.gbl...
Hi Rui,

What would you like your array to contain? Are you after a multi-dimensional array of Objects? Or a single-dimensional array of Somethings?

This is what the DataTable would be asking if it could. Given that it can't anticipate or ask, it offers a collection of Rows.

What did you have in mind?

Regards,
Fergus

Nov 20 '05 #6
the field values themselves

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> escreveu na mensagem
news:bo*************@ID-208219.news.uni-berlin.de...
* "Rui Sampainho" <rs********@hotmail.com> scripsit:
Is there any command to transfer the contents of a datatable to an
array.
Which part of the datatable do you want to store in an array?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #7
* "Rui Sampainho" <rs********@hotmail.com> scripsit:
the field values themselves


Have a look at Armin's suggestion...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #8
Hi Rui,

There's no way that the Table itself can do the job, for the reason hinted at before.

However, the Table does have the Rows Collection and each Row can provide an ItemArray which is an array of Objects. At
least this will save you having to address each item by name. Unfortunately you will still need to turn each Object into a
string, whether in your 2D array or deferred until the export. Can your export routine handle an array of arrays?

I think the Rows -> array -> Excel would be faster than exporting each Row separately, but you'd know better - you have
the fast array-export. Looking in my crystal ball I see some experimentation and timing tests in your future.

Sorry I can't be more definite. Good luck!

Regards,
Fergus
Nov 20 '05 #9
Cor
Hi Rui,

Why not bring the table to a dataset and then with dataset.writexml("file")
you have your xml file that you can read in your Excel spreadsheet.

I thought it was something untested
\\\\
ds as new dataset
ds.tables.add(yourtable)
ds.writexml("yourfile")
////

Cor

Nov 20 '05 #10

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

Similar topics

0
by: pavan | last post by:
hi, Please refer this article because that is the dll iam using for compression/decompression of datatables. http://www.eggheadcafe.com/articles/20031219.asp This is a windows application in C#...
0
by: pavan kumar | last post by:
hi, Please refer this article because that is the dll iam using for compression/decompression of datatables. http://www.eggheadcafe.com/articles/20031219.asp This is a windows application in C#...
2
by: Fredrik Rodin | last post by:
All, I've been looking around for a solution to my problem for a couple of days now. In short, here's my situation: 1. I'm getting a result from a component back as a datatable and I have...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
2
by: Niyazi | last post by:
Hi everyone, I have 5 string in my array that I get from MS Access DB. Public mDov(0) as string and I fill with my for loop. The result as shown below mDov(0) = "ABC_01" mDov(1) = "ABC_02"...
1
by: Maxwell2006 | last post by:
Hi, I am working with strongly typed datatables. What is the most efficient way to build a new DataTAble based on the result of DataTable.Select? At this point I use a foreach loop to do the...
6
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.