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




Reply With Quote
