• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1860
  • Last Modified:

.CSV import to DB through VB.NET

I need to write a program that imports data from .csv file into a database.

This was prev. being done through a dts that I created but the customers find it difficult to use the DTS even the documentation breaks it down very well.

Hello everyone

I am more of a sql/vbs scripter than a .net programmer so please try not to laugh at me

I need to access the .csv file which was .xls just saved as a .csv it has two rows

row1 = workspaces
row2 = extensions

I need to loop through row 1 and grab the workspaces and insert them into 7 tables
r2 will be done the same way but inserted into 3 tables

how do I access the .csv file and  how should I create those loops

please don't just tell the class can you also give me sample sytax on how to use the class

Thank you in advance
  • 2
  • 2
1 Solution
lojk.Net and Infrastructure ConsultantCommented:
Check my comments to a similar question in....

Bob LearnedCommented:
What version of .NET do you have?

conflikqAuthor Commented:
I have ver. 2005 pro
Bob LearnedCommented:
Cool b-)

I have been reading about the TextFieldParser.  Here is a class that should get you started on your way:

Imports Microsoft.VisualBasic.FileIO

Public Class CsvReader

    Public Sub ReadFile(ByVal fileName As String)

        Using reader As New TextFieldParser(fileName)

            reader.TextFieldType = FieldType.Delimited

            ' Set the delimiters for comma separated text
            reader.Delimiters = New String() {","}

            Dim currentRow As String()

            'Loop through all of the fields in the file.
            'If any lines are corrupt, report an error and continue parsing.
            While Not reader.EndOfData
                    currentRow = reader.ReadFields()
                    ' Include code here to handle the row.
                Catch ex As MalformedLineException
                    MsgBox("Line " & ex.Message & " is invalid.  Skipping")
                End Try
            End While
        End Using

    End Sub

End Class

conflikqAuthor Commented:
I'll try that


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now