Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization
Imports System.IO
Public Class Form1
Dim filePath As String
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim DataTb As DataTable
Private Sub BtnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBrowse.Click
Dim dpath As String
dpath = FolderBrowserDialog1.SelectedPath()
OpenFileDialog1.InitialDirectory = dpath
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName()
Dim objOpenFileDialog As New OpenFileDialog
With objOpenFileDialog
.DefaultExt = "txt"
'.FileName = "Test"
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
'.OverwritePrompt = True
.Title = "Open Text File"
End With
If objOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
'Open or Create the file
filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, objOpenFileDialog.FileName)
Call DisPlayTextFile()
Catch fileException As Exception
Throw fileException
End Try
End If
'Clean up
objOpenFileDialog.Dispose()
objOpenFileDialog = Nothing
End Sub
Private Sub DisPlayTextFile()
Dim myReader As New System.IO.StreamReader(filePath, System.Text.Encoding.Default)
' Dim myReader As New System.IO.StreamReader(filePath, System.Text.Encoding.UTF8)
' Dim myReader As New System.IO.StreamReader(filePath, System.Text.UnicodeEncoding.Default)
' Dim myReader As New System.IO.StreamReader(filePath, System.Text.Encoding.GetEncoding(874))
Dim Dt As New DataTable
Dim Dr As DataRow
Dim Line As String
Dt.Columns.Add("Part No", GetType(String))
Dt.Columns.Add("Part Name", GetType(String))
Dt.Columns.Add("Part Type", GetType(String))
Dt.Columns.Add("Std Pcs.", GetType(Decimal))
Dt.Columns.Add("Unit", GetType(String))
.......