Solved

Processing delimited file into a database

Posted on 2010-09-20
4
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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 Backup & Restore 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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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