我有一个 txt 格式的日志文件,我想将其导入访问数据库,作为测试,我做的第一件事是将其导入数据网格以检查我使用的代码是否可能如下:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using Reader As New Microsoft.VisualBasic.FileIO.
TextFieldParser(TextBox1.Text)
Reader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.FixedWidth
Reader.SetFieldWidths(8, 8)
Dim currentRow As String()
While Not Reader.EndOfData
Try
dg1.Rows.Clear()
currentRow = Reader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
dg1.Rows.Add(currentField)
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
End Using
End Sub
日志文件如下:
6/17/13 9:39AM 103 01 < DISA incoming >71857359 00:01'13" .... 0
6/17/13 9:37AM 102 04 < DISA incoming >71470674 00:03'18" .... 0
6/17/13 9:42AM 102 02 < DISA incoming >71759940 00:00'29" .... 0
6/17/13 9:41AM 103 03 < DISA incoming >71470674 00:01'59" .... 0
6/17/13 9:42AM 102 04 < DISA incoming >76441362 00:00'24" .... 0
6/17/13 9:43AM 103 02 < DISA incoming >70247389 00:01'35" .... 0
我试图至少导入前两个字段,它们是相应列下的日期和时间,但它似乎不起作用
谁能帮我将此日志解析到数据库中