.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
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
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

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
conflikqAuthor Commented:
I'll try that

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.