Solved

.NET error - Join of row.ItemArray in DataTable

Posted on 2009-07-08
2
779 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
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:MisterT25
ID: 31601336
VBrocks,

Thanks for your quick response.  I get the idea.

Thanks again
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Setting ACL permissions after creating user with DC replication lag possible? 5 41
Connection String 16 43
SQL Login 17 40
How to add <appSettings> to the webconfig file 2 21
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

16 Experts available now in Live!

Get 1:1 Help Now