I am trying to read to data from a .csv file and insert the data in a mysql database. The .csv file and the database have 4 columns.
I am able to insert the data to the database. The connections works fine, but i can't get the fields from the .csv file in the right fields in the database.
So how do i get a field from a .csv file in the same field in the database with the method i am using?
My code is similar to this:
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\ParserText.csv")
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.Delimiters = New String() {","}
Dim currentRow As String()
While Not MyReader.EndOfData
    Try
        currentRow = MyReader.ReadFields()
        For Each currentField As String In currentRow
            /*Use sql to insert data to database here*/
            cmd.commandText = "INSERT INTO mydatabase(column1, column2, column3, column4) VALUES(??, ??, ??, ??)"
            cmd.ExecuteNonQuery()
        Next 
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & ex.Message & " is invalid.  Skipping")
    End Try 
    End While 
End Using
 
     
     
     
    