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

VS 2019 textfileparser not working as expected - vb.net 4.6 - vs 2019 - mysql

$
0
0
Everything was working fine - now I am getting a SQL Syntax error. The textfileparser is passing the entire line, but not in double quotes, in single quotes which causes a problem as the Customer Concern has a single quote in it.

Here is the error:

MySql.Data.MySqlClient.MySqlException: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S NEEDED TO INSTALL NEW RUNNING LIGHTS - CHECK & ADVISE', '0.00', 'WAITING FOR A' at line 1'

Here is the Data which is coming in as a csv file - here is the line that I am having an issues with

"John's Auto Pros","1795 E. Valley Parkway","Escondido, CA. 92027","Phone - 760-741-2076 Fax - 760-741-6993","Current Technician Assignments","Report Date : 08/17/2021","Technician","Charged Hours","Pay Hours","Invoice / Estimate #","Hat Number","Job","Description","Status","Cody Carter",,"RO","CUSTOMER CONCERN / STATES: WHAT'S NEEDED TO INSTALL NEW RUNNING LIGHTS - CHECK & ADVISE",0.00,0.00,"WAITING FOR APPROVAL","24133","Totals:",8.26,8.26,"Grand Total Charged Hours: 64.02","Grand Total Pay Hours: 64.02","Page 1 of 1","(c) 2012 Mitchell Repair Information Company, LLC CurTechAssig.rpt 07.10.12"

This is the query that it is trying to insert

insert into johnsautopros.assignstagging (techname,rotype,vehicle,jobname,jobhours,jobstatus, ronumber) values ('Cody Carter', 'RO', '', 'CUSTOMER CONCERN / STATES: WHAT'S NEEDED TO INSTALL NEW RUNNING LIGHTS - CHECK & ADVISE', '0.00', 'WAITING FOR APPROVAL', '24133')

Here is my code - Forgive me, I am not a programmer, at least not for 40 years now, and then it was assembler.
Code:

Private Sub parser()


        Using MyReader As New Microsoft.VisualBasic.
                      FileIO.TextFieldParser("C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\currentassign.csv")
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(",")
            Dim currentRow As String()
            While Not MyReader.EndOfData
                Try
                    currentRow = MyReader.ReadFields()
                    Dim currentField As String
                    Dim i As Integer
                    For i = 1 To 29
                        For Each currentField In currentRow
                            drow(i) = currentField
                            If i < 30 Then

                                i = i + 1
                            End If
                        Next
                        techname1 = drow(15)
                        rotype1 = drow(17)
                        vehicle1 = ""
                        jobname1 = drow(18)
                        jobhours1 = drow(19)
                        jobstatus1 = drow(21)
                        ronumber1 = drow(22)
                        putdrow()
                    Next
                Catch ex As Microsoft.VisualBasic.
                            FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message &
                    "is not valid and will be skipped.")
                End Try
            End While
        End Using
    End Sub

Private Sub putdrow()
        sqlConn = New MySqlConnection
        sqlConn.ConnectionString = "Server =" + server + ";" + "user id = " + username + ";" _
            + "password =" + password + ";" + "database =" + database
        Dim Query As String
        Dim reader As MySqlDataReader
        sqlConn.Open()
        Query = "insert into johnsautopros.assignstagging (techname,rotype,vehicle,jobname,jobhours,jobstatus, ronumber) values ('" & techname1 & "', '" & rotype1 & "', '" & vehicle1 & "', '" & jobname1 & "', '" & jobhours1 & "', '" & jobstatus1 & "', '" & ronumber1 & "')"
        sqlCmd = New MySqlCommand(Query, sqlConn)
        reader = sqlCmd.ExecuteReader
        sqlConn.Close()
    End Sub


Viewing all articles
Browse latest Browse all 15661

Trending Articles



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