Hello all. I am trying to catch insert errors for imported *.csv files. with my current code, any rows of data that do not meet the constraints of the table are simply skipped... I would like to throw an exception so I can send the "bad" records to a container on the front end and allow a user to examine and delete/correct the issue and then insert the modified records. Can this be done or should I LOAD DATA INFILE to a constraint-free table then run and insert and catch the errors there?
If this question should be limited to just the
thank you in advance.
Chris
Imports MySql.Data.MySqlClient
Public Class Form1
Dim flName As String = "C:\\a1\\DATA\\101 3089.csv"
Dim var1 As String = "101 3089"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim conn As MySqlConnection = New MySqlConnection
conn.ConnectionString = "server=192.168.0.2;" & _
"user id=root;" & _
"password=**********;" & _
"database=db1"
Dim com As MySqlCommand = New MySqlCommand
conn.Open()
With com
Try
.CommandText = "LOAD DATA LOCAL INFILE '" & flName & "' INTO TABLE csvTest" & _
" FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'" & _
" (idcsvTest,bLen,bWid,bMinLen,bMaxLen,bWid1,bWid2,bWid3,bAvgWid) " & _
"SET ticknum='" & var1 & "';"
.Connection = conn
.ExecuteNonQuery()
Catch oops As MySqlException
MsgBox("MySQl says: " & oops.ErrorCode & "-" & oops.Message)
'Do catchy stuff...
End Try
End With
conn.Close()
conn.Dispose()
conn = Nothing
End Sub
End Class
If this question should be limited to just the
LOAD DATA INFILEstatement, please let me know and I will ask in the general MySql area instead.
thank you in advance.
Chris