Solved

Processing delimited file into a database

Posted on 2010-09-20
4
401 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

770 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