Question Select into outfile Query... how to avoid writing BOMs

Tazo85

Member
Joined
Aug 31, 2012
Messages
7
Programming Experience
Beginner
Hello...

below is my code:

VB.NET:
Try
            'create export directory if needed
            If (Not System.IO.Directory.Exists(Trim(TextBox64.Text))) Then
                System.IO.Directory.CreateDirectory(Trim(TextBox64.Text))
            End If

        Catch es As Exception
        End Try

        conn = New MySqlConnection()
        Randomize()
        Dim tt As Integer = CInt(Int((1000000 * Rnd()) + 1))

        conn.ConnectionString = "server=" & Form4.TextBox1.Text & ";" _
         & "port=" & Form4.TextBox5.Text & ";" _
         & "user id=" & Form4.TextBox2.Text & ";" _
         & "password=" & Form4.TextBox3.Text & ";" _
         & "database=" & Form4.TextBox4.Text & ";" _
         & "Character Set=utf8;"

        Dim strSQL As String
        strSQL = "SELECT * FROM labor_actual where PROJECT LIKE '%" & ComboBox32.Text & "%' AND FIRSTNAME LIKE'%" & ComboBox34.Text         & "%' AND LASTNAME LIKE '%" & ComboBox33.Text & "%'" _
            & " INTO OUTFILE" & "'" & Trim(TextBox64.Text) & "Labor_Actulas_Search_Query_Results" & "-" & tt & "." & "csv" & "'" _
            & " FIELDS TERMINATED BY ',' ENCLOSED BY '" & "'" _
            & " LINES TERMINATED BY '\n'"

        Dim oCmd As New MySqlCommand(strSQL, conn)

        Dim exc As Exception = Nothing

        Try
            conn.Open()
            oCmd.ExecuteNonQuery()
            MsgBox("csv file was created in " & TextBox64.Text & " folder")
        Catch ex As Exception
            exc = ex

        Finally
            If Not exc Is Nothing Then
                MsgBox("Error: " & exc.Source & " - " & exc.Message)
                conn.Close()

            Else
                conn.Close()

            End If
            If (Not conn Is Nothing) AndAlso (conn.State = ConnectionState.Open) Then
                conn.Close()
            End If
            
        End Try

it works fine but my db contains utf8 characters and when I open the csv file it contains strange characters. Can I avoid writing BOMs somehow? I assume BOM is causing this since the txt export looks great. I want to avoid using stream writer. This method is simple and works great form my needs with the exception of this issue.

Thanks.
 
Back
Top