用split分解文本文件中的行数据,然后插入数据库时出现错误,麻烦指导,谢
chcpu 2004-04-12 09:11:15 烦请你看看,错在哪里
下面的代码,是将形如以下文本文件的数据灌入access数据库
0307 我
0760 的
0125 便
0723 很
0224 後
……
如果我不将strline 分解作为整体插入不会出错,但是一旦用上
arrline = Split(strline, vbCrLf)进行数据分割(字和编码),马上就有错误提示:
compile error:
can't assign to array
代码如下:
Private Sub Command1_Click()
Dim astr As String
Dim resultMDB As Database
Dim strline As String
Dim arrline(2) As String
Open App.Path & "\jiandan.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strline
arrline = Split(strline, vbCrLf)
Set resultMDB = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\test.dat")
astr = "INSERT INTO jiandan(bianma,wenzhi) values ('" & arrline(0)&" ','" & strline(1) & "')"
resultMDB.Execute astr
Loop
resultMDB.Close
Set resultMDB = Nothing
Close #1
End Sub