Solved

Processing delimited file into a database

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

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now