473,804 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17713
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********@hot mail.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*******@free net.de> schrieb
Untested:
A DataTable implements the interface ICollection. The interface has a
CopyTo method.


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

Sorry.
--
Armin

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

Nov 20 '05 #4
* "Rui Sampainho" <rs********@hot mail.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.co m> escreveu na mensagem
news:OM******** ******@TK2MSFTN GP10.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********@hot mail.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********@hot mail.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.writexm l("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(y ourtable)
ds.writexml("yo urfile")
////

Cor

Nov 20 '05 #10

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

Similar topics

0
1572
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# & iam using remoting extensively for my database layer. In the remote server iam having a method which returns byte instead
0
1428
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# & iam using remoting extensively for my database layer. In the remote server iam having a method which returns byte instead of
2
3181
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 no option to sort the different columns during the call to the component.
0
3169
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 datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
3
5419
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 example first:
2
2025
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" mDov(2) = "ABC_03" mDov(3) = "ABC_04"
1
5742
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 work manually. I am looking for an automated way. Thank you, Max
6
2358
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 so I can do this: myDataTable.Rows.Add(array()) instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")
0
2198
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 CSV file without any issues only if all the fields are not null. If any field is blank, it moves the values to the left and displays the value under invalid column. Example is shown below: A part of CSV file. I am reading the first row as...
0
9711
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
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
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
10335
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
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.