Solved

Processing delimited file into a database

Posted on 2010-09-20
4
402 Views
Last Modified: 2012-05-10
I have several semicolon-delimited files which contain hundreds of thousands of records in each. My objective is to reliably import them into a MS SQL database that I set up. I figured the easiest way to do this was to write a simple VB.NET application to process it.

The tricky part is that the values in the columns are not contained in quotes, and the last column has values that actually contain semicolons. There are a total of 5 columns.

Does anyone have recommendations on how I can best import these files into MS SQL?
0
Comment
Question by:elorc
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
ladarling earned 500 total points
ID: 33716769
If you know that columns 1 through 4 will not contain semicolons, you can reliably use the Split() function on the semicolon to break the rows down into values, since you will know that the first 4 members of the array will map to columns 1 through 4, and that all indexes after 3 (the fourth index in the array) need to be concatenated back into column5, below is a prototype of that scenario....
 

        Dim sr As New IO.StreamReader("c:\somefile.txt")

        While Not sr.EndOfStream
            Dim values() As String = Split(sr.ReadLine, ";")
            For i = 0 To 3 'These are the first 4 columns
                'Do something values(i)
            Next
            Dim col5 As String = String.Empty
            For i = 3 To UBound(values) ' These will all be parts of column 5
                col5 &= values(i)
            Next
            'Do something with col5 here then move on to the next row
        End While

Open in new window

0
 
LVL 11

Assisted Solution

by:ladarling
ladarling earned 500 total points
ID: 33716803
Oops... that should actually be:
For i = 4 To UBound(values) ' These will all be parts of column 5
                col5 &= values(i)
Next
 
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33717988
Can you not use the Import/Export wizard?
0
 
LVL 1

Author Comment

by:elorc
ID: 33724946
Kaufmed: I can't. The import/export wizard is unreliable. I tried it initially but as expected it failed with cryptic error messages.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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