Solved

.NET error - Join of row.ItemArray in DataTable

Posted on 2009-07-08
2
787 Views
Last Modified: 2013-11-26
I have some data in a DataTable.  I want to write it to a tab delimited file.

In the following code I am getting this error on the Join command:
System.ArgumentException: Argument 'SourceArray' cannot be converted to type 'String'.

I am using VS 2008 and .NET 2.0.  Thanks for any ideas.
Dim row As DataRow
Using sOut As New StreamWriter(tabFileName)
       For Each row In dt.Rows
               sOut.WriteLine(Join(row.ItemArray, vbTab))
        Next
End Using

Open in new window

0
Comment
Question by:Tom Sage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 24808904
That's because not all columns are Strings.

You'll have to do it like this:

        Dim delimiter As String = String.Empty
        For Each row As DataRow In dt.Rows

            delimiter = String.Empty
            For i As Integer = 0 To dt.Columns.Count - 1

                sOut.Write(delimiter & row.Item(i).ToString())

                delimiter = vbTab

            Next

            sOut.WriteLine("")

        Next

0
 

Author Closing Comment

by:Tom Sage
ID: 31601336
VBrocks,

Thanks for your quick response.  I get the idea.

Thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question