我正在尝试两个文件:1。一个包含经销商代码和每行每单位销售数量的6行的文本文件(例如010,64)。我拼出两个元素并将它们分配给变量。接下来,我试图遍历SQL表并通过匹配经销商代码更新销售数据。
我遇到的问题是内部循环(SQL更新)更新了外部循环中每个经销商的销售数据,因为SQL表中的每一行都会丢弃数字。例如,两个经销商在文本文件的第1行和第2行各自的单位销售额:010,64和020,72。内部循环将使用两个销售数字(64和72)更新第一个经销商,而不是首先继续更新第二个。我知道问题在于我构建循环。任何帮助表示赞赏。
If fso.FolderExists(sourceLocation) Then
Set fileList = fso.GetFolder(sourceLocation).Files
For Each fileFound In fileList
Set folder = fso.GetFolder(sourceLocation)
upd_date = CStr(FormatDateTime(Date(),2))
If fso.FolderExists(sourceLocation) Then
Set fileList = fso.GetFolder(sourceLocation).Files
For Each fileFound In fileList
If fso.FileExists(fileFound) Then
Set ReturnNoFileToRead = fso.OpenTextFile(fileFound)
Do While Not ReturnNoFileToRead.AtEndOfStream
readLine = ReturnNoFileToRead.ReadLine
If Not IsNumeric(Left(readLine,1)) Then
alphaLine = Split(readline,",")
upd_date = Left(alphaLine(0),20)
insertDate = "UPDATE soavehreports SET rep_date = '" + upd_date _
+ "' WHERE rep_type = 'CUR' "
sneConnection.Execute(insertDate)
ElseIf IsNumeric(Left(readLine,1)) Then
intLine = Split(readline,",")
intLine(1) = CInt(intLine(1))
For row = 0 to RowCount -2
distnum = Trim(tableArray(r, 0))
daily = CInt(Trim(tableArray(r, 2))) + intLine(1)
tenday = CInt(Trim(tableArray(r, 3))) + intLine(1)
mtdsales = CInt(Trim(tableArray(r, 4))) + intLine(1)
ytdsales = CInt(Trim(tableArray(r, 5))) + intLine(1)
currinvt = CInt(Trim(tableArray(r, 8))) - intLine(1)
totaval = CInt(Trim(tableArray(r, 9))) - intLine(1)
mtdpercent = CDbl(Trim(tableArray(r, 12)))
ytdpercent = CDbl(Trim(tableArray(r, 13)))
UpdateCmd1 = "UPDATE vedlynat_new SET daily = '" + CStr(daily) _
+ "', tenday = '" + CStr(tenday) + "', mtdsales = '" _
+ CStr(mtdsales) + "', "
UpdateCmd1 = UpdateCmd1 + "ytdsales = '" + CStr(ytdsales) _
+ "', currinvt = '" + CStr(currinvt) + "', totaval = '" _
+ Cstr(totaval) + "', proc_date = '" + upd_date + "' "
UpdateCmd1 = UpdateCmd1 + "WHERE distnum = '" + intLine(0) _
+ "' AND distnum <> '999'"
sneConnection.Execute(UpdateCmd1)
Next
End If
Loop
ReturnNoFileToRead.Close
sneConnection.close
End If
Next
End If
文字档案:
010,64
020,62
050,155
060,136
080,127
SQL表:
distnum daily tenday mtdsales ytdsales
010 0 0 0 0
020 0 0 0 0
050 0 0 0 0
060 0 0 0 0
080 0 0 0 0