文本格式
"11","22","33",
"11","22","33",
"11","22","33",
sql
Private Sub Command2_Click()
Dim ag As String
With CommonDialog2
CommonDialog2.Filter = "Text[*.TXT]|*.txt"
CommonDialog2.ShowOpen
ag = CommonDialog2.FileName
Text2.Text = ag
End With
If ag = "" Then
Exit Sub
End If
Conn3.Execute ("delete from [ztry]")
If Rst.State <> adStateClosed Then Rst.Close
Rst.Open "select * from pm", Conn3, adOpenKeyset, adLockBatchOptimistic
Open ag For Input As #1
Do Until EOF(1)
Input #1, N1, N2, N3
'寫入資料庫
strSQL = "INSERT into pm(欄位1,欄位2,欄位3) values (" & "'" & N1 & "'," & "'" & N2 & "'," & "'" & N3 & "'" & ")"
Conn3.Execute strSQL
Loop
MsgBox "錄入完畢", vbInformation, "資料錄入"
Close #1
End Sub
文本中有逗號,不能匯入,請大俠修改!看line input ,但不會寫代碼
uj5u.com熱心網友回復:
不需要寫程式,直接在access里以csv格式匯入即可。uj5u.com熱心網友回復:
如果是逗號分隔的“標準”文本格式,可以將其當作 Jet Engine 的外部資料庫來匯入。其實,即便是用你這樣的方法逐行匯入,也是可行的。
Dim N() As String, tmp As String
Do Until EOF(1)
Line Input #1, tmp
N = Split (tmp, ",")
If Ubound(N) = 2 Then
'寫入資料庫
strSQL = "INSERT into pm(欄位1,欄位2,欄位3) values (" & "'" & N(0) & "'," & "'" & N(1) & "'," & "'" & N(2) & "'" & ")"
Conn3.Execute strSQL
End If
Loop
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/115379.html
上一篇:請問怎么使用VB實作串口通信?
下一篇:用VBA抓取網頁資料
