ok, thanks u all,
I find the solution to solve, that is: I will import all content with # delimited into a table called Import in Access and after that i will export this table into a datagridview and then i will export it into other text file, but i get errors when i import txt file into Access. This is my code:
Name of text file: BC0902281.A0131700101 -> i get id from a part of txt name : 01317001.
Content of txt file:
BG#01317001#D01#
20090228#5#D0101#1274193999025#
20090228#5#D0102#1227149540626#
EN#01317001#D01#2#
BG#01317001#A0101#
these lines contain EN and BG must not be inserted into acess
CODE
Private Function sqlInsert(ByVal id As String, ByVal name As String, ByVal info As String, ByVal qual As double, ByVal datetime As String) As String
Dim sql As String
sql = ""
sql = sql & "INSERT INTO IMPORT (id, name, info, qual, datetime) VALUES("
sql = sql & "'" & id & "' "
sql = sql & ",'" & name & "' "
sql = sql & ",'" & info & "' "
sql = sql & ",'" & qual & "' "
sql = sql & ",'" & datetime & "' "
sql = sql & ")"
sqlInsert = sql
End Function
Private Sub btnFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileName.Click
Dim Conn As New System.Data.OleDb.OleDbConnection
Dim Comm As New System.Data.OleDb.OleDbCommand
Dim i As Integer
Dim arrLine As String()
Dim arrLines As String()
Dim strFileName As String
Dim sql As String
Dim rsl As DialogResult
Conn.ConnectionString = getConnectionString_MSACCESS("\\server\Data\test\SELECT_FILES\db1.mdb", "", "")
Conn.Open()
Comm.Connection = Conn
With Me.OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.Multiselect = True
.Title = "Text files Browser"
rsl = .ShowDialog()
If rsl = Windows.Forms.DialogResult.OK Then
For Each s As String In OpenFileDialog1.FileNames
Dim fi = OpenFileDialog1.FileName
strFileName = IO.Path.GetFileName(s)
txtText.Text = fi
MessageBox.Show(strFileName)
arrLines = System.IO.File.ReadAllLines(strFileName)
Dim id, name, info, qual, datetime As String
id = ""
datetime = ""
If arrLines.Length > 0 Then
datetime = arrLines(0).ToString()
arrLine = arrLines(0).ToString().Split("#")
datetime = arrLine(1).Substring(4, arrLine(1).Length - 4)+ "/" + arrLine(1).Substring(2, 2) + "/" + arrLine(1).Substring(0, 2)
id = strFileName.Substring(strFileName.Length - 14, 8)
End If
For i = 1 To arrLines.Length - 1
arrLine = arrLines(i).ToString().Split("#")
If arrLine(0) <> "EN" And arrLine.Length = 4 Then
name = arrLine(0)
info = arrLine(1)
qual = arrLine(2)
sql = sqlInsert(id, name, info, qual, datetime ) Comm.Connection = Conn
Comm.CommandText = sql
Comm.ExecuteNonQuery()
End If
Next
Next
MessageBox.Show("Sucessfully!")
End If
End With
End Sub
plz help me. thanks
This post has been edited by meloco: 6 Apr, 2009 - 07:03 PM