Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15713

VS 2019 MySQL Bulk Loader from .csv without column names

$
0
0
I have the following vb.net code to load a .csv file very fast into a MySQL table :

Code:

Dim bl As New MySqlBulkLoader(conn)
        bl.TableName = "elektrisiteit_staging"
        bl.FieldTerminator = ","
        bl.LineTerminator = "\r\n"
        bl.FileName = InvoerFile
        bl.NumberOfLinesToSkip = 3
        bl.FieldQuotationCharacter = """"
        bl.Columns.AddRange({"@Datum", "TimeOfUse", "UnitsOfMeasurement", "Verbruik", "@EnergyCharge"})
        bl.Expressions.Add("Datum = STR_TO_DATE(@Datum, '%d-%m-%Y')")
        bl.Expressions.Add("EnergyCharge =  Replace((substring(@EnergyCharge, instr(@EnergyCharge, 'R') + 1)),',','') ")



        Try
            conn.Open()
            Dim count As Integer = bl.Load()
            '' MsgBox("Inside try")
            '' conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try


However how do I handle that if the .csv does not have headers ?

From MySQL I understand you can use


Code:

(column1, column2, @column3, ...)
How can I use the above in a VB.net command. I have tried removing the quotes, replacing the names with column1,column2 etc.
Also I think the bl.Columns.AddRange is wrong. I still want to do column mapping using user variables.

Viewing all articles
Browse latest Browse all 15713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>