新手求助:把文本文件导入到access数据库,有代码
Private Sub Command1_Click()
Dim fsys As Scripting.FileSystemObject
Dim frec As String
Dim ftext() As String
Dim fdate As Date
Dim count As Integer
Dim frushtime As Date
Set fsys = CreateObject("scripting.filesystemobject")
Set fstream = fsys.OpenTextFile("d:\flw.txt", ForReading)
Dim conn As New ADODB.Connection
conn.Open "dsn=netflow;uid=xiaxuan;pwd=sym"
Do While fstream.AtEndOfStream = False
frec = fstream.ReadLine
ftext = Split(frec, ",")
If InStr(Trim(ftext(9)), "-") = 1 Then
fip = ftext(10)
fport = ftext(11)
Else
fip = ftext(9)
fport = ""
End If
fdate = ftext(4) & " " & ftext(5)
fname = ftext(1)
If Weekday(fdate) = vbSunday Or Weekday(fdate) = vbSaturday Then
Else
If (ftext(5) > #8:30:00 AM# And ftext(5) < #12:00:00 PM#) Or (ftext(5) > #1:30:00 PM# And ftext(5) < #6:00:00 PM#) Then
MsgBox "属于符合条件的记录,导入到数据库!”"
conn.Execute "insert into tbflow (name,ondate,ip,port) values (fname,fdate,fip,fport)" ______此处问题大大的,就是把访问日志导入数据库
我没有分了!?
Else
End If
End If
Loop
conn.Close
Set conn = Nothing
frushtime = Now()
lbltime.Caption = "您更新数据库的时间是" & frushtime
End Sub