Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:28:04+00:00 2026-05-15T05:28:04+00:00

This should be an easy one, looks like I got myself too confused. I

  • 0

This should be an easy one, looks like I got myself too confused.

I get a table from a database, data ranges from varchar to int to Null values. Cheap and dirty way of converting this into a tab-delimited file that I already have is this (shrunken to preserve space, ugliness is kept on par with original):

da.Fill(dt)
' da - DataAdapter '
' dt - DataTable '
Dim lColumns As Long = dt.Columns.Count
Dim arrColumns(dt.Columns.Count) As String
Dim arrData(dt.Columns.Count) As Object

Dim j As Long = 0
Dim arrData(dt.Columns.Count) As Object

For i = 0 To dt.Rows.Count - 1

    arrData = dt.Rows(i).ItemArray()

    For j = 0 To arrData.GetUpperBound(0) - 1
        arrColumns(j) = arrData(j).ToString
    Next

  wrtOutput.WriteLine(String.Join(strFieldDelimiter, arrColumns))

  Array.Clear(arrColumns, 0, arrColumns.GetLength(0))
  Array.Clear(arrData, 0, arrData.GetLength(0))
Next

Not only this is ugly and inefficient, it is also getting on my nerves. Besides, I want, if possible, to avoid the infamous double-loop through the table. I would really appreciate a clean and safe way of rewriting this piece.

I like the approach that is used here – especially that is trying to solve the same problem that I have, but it crashes on me when I apply it to my case directly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:28:05+00:00Added an answer on May 15, 2026 at 5:28 am

    You should be able to do just like this:

    File.WriteAllText( _
      fileName, _
      String.Join( _
        Environment.NewLine, _
        dt.Rows.Cast(Of DataRow)().Select( _
          Function(r) String.Join( _
            ",", _
            r.ItemArray().Select(Function(o) o.ToString()).ToArray() _
          ) _
        ).ToArray() _
      ) _
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should be an easy one. I thought, from reading this blog post that I
This one should be easy. I have a Reviews table with records. The columns
This should be and easy one for the LINQ gurus out there. I'm doing
This should be easy (at least no one else seems to be having a
This one should be easy. I just can't figure out what to search for...
OK, I'm feeling like this should be easy but am obviously missing something fundamental
Possible Duplicate: Property Name and need its value Hi, This one should be easy
This is possibly an easy one that I can't seem to get past. I've
This should be easy, but I cannot seem to get it right as I
This should be an easy one. I have a variable that I've already declared

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.