Solved

Processing delimited file into a database

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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