2012年2月2日 星期四

csv 中文讀不出來

參考引用
--
依來源,我稍調整讀取的編碼方式(這取決匯出的編碼原則)
    Public Function CSVFileToDT(ByVal FullFileName As String) As DataTable
        Dim newDataTable As New DataTable
        Dim CloumnNameFlag As Boolean = True
        Using sr As IO.StreamReader = New IO.StreamReader(FullFileName,System.Text.Encoding.Default)
            Dim Tempstr As String = Nothing
            Tempstr = sr.ReadLine
            While Tempstr IsNot Nothing
                If CloumnNameFlag = True Then
                    For i As Integer = 0 To Tempstr.Split(",").Length - 1
                        newDataTable.Columns.Add(Tempstr.Split(",")(i))
                    Next
                    CloumnNameFlag = False
                Else
                    Dim row As DataRow = newDataTable.NewRow
                    For i As Integer = 0 To Tempstr.Split(",").Length - 1
                        row.Item(i) = Tempstr.Split(",")(i)
                    Next
                    newDataTable.Rows.Add(row)
                End If
                Tempstr = sr.ReadLine
            End While
            sr.Close()
        End Using
        Return newDataTable 
End Function

---
以上這組能解決使用 OleDB 讀取 csv 後一些碼不見的問題!
PS:被這問題困了2-3小時

沒有留言:

張貼留言