I am importing data from a csv file into my vb.net application. Below is the current code I am using to achieve this:
Dim myImportConnectionString As String = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & txtboxSelectFile.Text & "';Extended Properties=""Excel 8.0;IMEX=1""" Dim MyImportConnection As New System.Data.OleDb.OleDbConnection MyImportConnection.ConnectionString = myImportConnectionString MyImportConnection.Open() Dim myImportAdapterString As String = "select * from [" & mySheet & "$]" Dim MyImportCommand As New System.Data.OleDb.OleDbCommand(myImportAdapterString, MyImportConnection) Dim myImportDataAdapter As New System.Data.OleDb.OleDbDataAdapter(MyImportCommand) Dim myImportDataTable As New System.Data.DataTable myImportDataAdapter.Fill(myImportDataTable) dgvFirst.DataSource = myImportDataTable myImportDataAdapter.Dispose() MyImportCommand.Dispose() MyImportConnection.Close() MyImportConnection.Dispose() GC.Collect() The problem I have is that the data is UTF8 encoded. When I import it, any special characters are being displayed incorrectly. The only way I can open the csv file and use the correct encoding is by opening it manually, using Excel, and importing the data to a new Excel file.
Is there any way I can specify the encoding to use when the file is being automatically imported into a vb.net datatable so that foreign characters are displayed correctly?
Many Thanks :)