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()
i have these codes to actually replace the tabs delimiter to commas in my text file and insert them into access database. but im receiving this error: "No value given for one or more parameters" Anyone tell me whats wrong?
if i remove the part for the replacement of delimiters, and select a pure CSV file, it works fine.