txt导入access,
本帖最后由 bcrun 于 2013-10-28 10:23:45 编辑
Private Sub Command1_Click()
Dim item_subno, barcode, item_name As String
Dim sale_price As Double
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wj.mdb;User ID=admin;Password=;Jet OLEDB:Database Password=123" '连接ACCESS数据库Con.Open
Open App.Path & "\aa.txt" For Input As #1
Do While Not EOF(1)
Input #1, item_subno, barcode, item_name, sale_price
Con.Execute ("insert into spzlk(item_subno,barcode,item_name,sale_price) values( " & item_subno & "," & barcode & "," & item_name & " , " & sale_price & " )")
Loop
Close #1
ErrHandler:
' 用户按了“取消”按钮
Exit Sub
End Sub
Dim strItem() As String, strLine As String
'......
Open App.Path & "\aa.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
strItem = Split(strLine, vbTab)
If Ubound(strItem) = 3 Then Con.Execute ("insert into spzlk(item_subno,barcode,item_name,sale_price) values('" & strItem(0) & "','" & strItem(1) & "','" & strItem(2) & "'," & strItem(3) & ")")
Loop
Close #1