Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

.NET error - Join of row.ItemArray in DataTable

Posted on 2009-07-08
2
Medium Priority
?
798 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
2 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

782 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