Dim connect As String connect = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\segdata.accdb" Dim conn As New OleDbConnection(connect) Dim sr As System.IO.StreamReader Dim entirefile As String sr = File.OpenText(Application.StartupPath & "\SEG1.txt") entirefile = sr.ReadToEnd() ' Read the whole file Dim OriginalValue As String OriginalValue = vbTab Dim ReplaceValue As String ReplaceValue = "," entirefile = entirefile.Replace(OriginalValue, ReplaceValue) sr.Close() 'write Dim sw As IO.StreamWriter = File.CreateText(Application.StartupPath & "\SEG1.txt") sw.Write(entirefile) sw.Close() Dim query As String = "INSERT INTO SEGDATA (School, Campus, AdminNo, ModuleCode, ModuleGrp) " & _ "SELECT F1 as School, F2 as Campus, F3 as AdminNo, F4 as ModuleCode, F5 as ModuleGrp FROM [Text;DATABASE=" & System.IO.Path.GetDirectoryName(Me.OpenFileDialog1.FileName) & ";HDR=NO].[" & Me.OpenFileDialog1.SafeFileName & "]" Dim cmd As OleDbCommand = New OleDbCommand(query, conn) conn.Open() cmd.ExecuteNonQuery() cmd.Dispose() conn.Close()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)