新手请教程序运行不了(太穷了只有14分,给你10 分)
想把txt文件保存到数据库中可是程序运行到 rs(7).Value = Trim(fdArray(7))运行不下去提示:
全部程序如下:
Private Sub Command2_Click()
Dim intFreeNumber As Integer
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rsArray() As String, fdArray() As String
Dim i As Long, j As Long
Dim strTemp As String
Dim strfile As String
intFreeNumber = FreeFile()
Open App.Path & "\aa.txt" For Binary As #intFreeNumber
Do While Not EOF(intFreeNumber)
strTemp = Input(intFreeNumber, #intFreeNumber)
strfile = strfile & strTemp
Loop
Close #intFreeNumber
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
conn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select *from [MCOMSITE]", conn, 1, 3
rsArray = Split(strfile, vbCrLf)
For i = 1 To UBound(rsArray)
fdArray = Split(rsArray(i), vbTab)
For j = 1 To 20
rs.AddNew
rs(0).Value = Trim(fdArray(0))
rs(1).Value = Trim(fdArray(1))
rs(2).Value = Trim(fdArray(2))
rs(3).Value = Trim(fdArray(3))
rs(4).Value = Trim(fdArray(4))
rs(5).Value = Trim(fdArray(5))
rs(6).Value = Trim(fdArray(6))
rs(7).Value = Trim(fdArray(7))
rs(8).Value = Trim(fdArray(8))
rs(9).Value = Trim(fdArray(9))
rs(10).Value = Trim(fdArray(10))
rs(11).Value = Trim(fdArray(11))
rs(12).Value = Trim(fdArray(12))
rs(13).Value = Trim(fdArray(13))
rs(14).Value = Trim(fdArray(14))
rs(15).Value = Trim(fdArray(15))
rs(16).Value = Trim(fdArray(16))
rs(17).Value = Trim(fdArray(17))
rs(18).Value = Trim(fdArray(18))
rs(19).Value = Trim(fdArray(19))
rs(20).Value = Trim(fdArray(20))
Next j
Next i
rs.UpdateBatch
Set rs = Nothing
Set conn = Nothing
End Sub
内容附件:
2.rar
(39.52 KB)