I need to insert six txt files into MySQL tables. I want to insert the file txt10.txt into table D1, the file txt20.txt into table D2, the file txt30.txt into table D3, etc. But all text files are inserted into all MySQL tables.
My code below:
Arr1 = Array("txt10", "txt20", "txt30", "txt40", "txt50", "txt60")
Arr2 = Array("D1", "D2", "D3", "D4", "D5", "D6")
For K = 0 To UBound(Arr1)
For I = 0 To UBound(Arr2)
SQL = " FLUSH TABLE `tbl_" & Arr2(I) & "_" & Year(Date()) & "`; "
cn.Execute(SQL)
SQL = " LOAD DATA LOCAL INFILE 'D:\\nOpen\\" & Arr1(K) & ".txt' "
SQL = SQL & " INTO TABLE `tbl_" & Arr2(I) & "_" & Year(Date()) & "` FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
cn.Execute(SQL)
Next
Next
EDIT #1
In your code I have error:
Array index out of range
On this line:
tbl = Arr2(n)
New code:
Arr1 = Array("txt10", "txt20", "txt30", "txt40", "txt50", "txt60")
Arr2 = Array("D1", "D2", "D3", "D4", "D5", "D6")
For n=0 To UBound(Arr1)
txt = Arr1(n)
tbl = Arr2(n)
SQL = " FLUSH TABLE `tbl_" & tbl & "_" & Year(Date()) & "`; "
cn.Execute(SQL)
SQL = " LOAD DATA LOCAL INFILE 'D:\\nOpen\\" & txt & ".txt' "
SQL = SQL & " INTO TABLE `tbl_" & tbl & "_" & Year(Date()) & "` FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
cn.Execute(SQL)
Next