Home > Software engineering >  Vb implementation choice TXT file import ACCes database
Vb implementation choice TXT file import ACCes database

Time:10-25

TXT file is as follows:
51 y9, 73090700001-0001, 0056100, 1, 0.115, 5, 7909-0009-24547, 9099-0009-2454,
51 y9, 73090700002-0001, 0056100, 1, 0.115, 5, 9200-0032-7016, 1920-0032-70161,,

The database is as follows:

No FSC Qty Site Weight BoxType BBID
51 y9 0.115 5, 73090700001-0001, 56100 1 9099-0009-2454 7

The code is as follows:
 Private Sub Command2_Click () 
Dim SZSQL $
Dim no, FSC
Dim combo1
Set the CNN=New ADODB. Connection

If combo1. Text="" Then
MsgBox "please select import data!" VbInformation, "tip"
The Else
CNN. The ConnectionString="Provider=Microsoft. Jet. The OLEDB. 4.0;" & "Data Source=db. MDB" 'connection Data
CNN. ConnectionTimeout=30
CNN. Open

The Open combo1. Text For Input As # combo1. Text
The Do While Not EOF (1)
Input # combo1. Text, no, FSC
SZSQL="insert into PD (no, FSC) values ('" & amp; Trim (no) & amp; "', '" & amp; Trim (FSC) & amp; "')
"CNN. The Execute (SZSQL)
Loop
Close # 1
Cnn.Com mitTrans
MsgBox "complete"
End the If
End Sub

CodePudding user response:

 
Private Sub Command2_Click ()
Dim Arr () As String, FN As an Integer, the Data As String
Set the CNN=New ADODB. Connection
If Len (Dir (combo1. Text))=0 Then
MsgBox "please select import data!" VbInformation, "tip"
The Else
CNN. The ConnectionString="Provider=Microsoft. Jet. The OLEDB. 4.0;" & "Data Source=" & amp; The Replace (App. Path & amp; "\ db MDB", "\ ", "") 'connection data
CNN. Open
FN=FreeFile
The Open combo1. Text For Input As FN
Do Until EOF (FN)
The Line Input # FN, Data
If InStr (Data, ", ") & gt; 0 Then
Arr=Split (Data, ", ")
'in the database fields and the content in the TXT file corresponding relation deal with yourself, you are not clear
CNN. The execute "insert into PD (no, FSC) values ('" & amp; Arr (0) & amp; "', '" & amp; Arr (1) & amp; "')
"End the If
Loop
Close # FN
CNN. Close
MsgBox "complete"
End the If
The Set of CNN=Nothing
End Sub
  • Related