Solved

.NET error - Join of row.ItemArray in DataTable

Posted on 2009-07-08
2
776 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:MisterT25
2 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
Comment Utility
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:MisterT25
Comment Utility
VBrocks,

Thanks for your quick response.  I get the idea.

Thanks again
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now