VB.net SQL output loop rename file error on next loop

62 Views Asked by At

new to the stack here. I am developing some tools for work that allow us to pull information from a database and then operate on it with additional custom code. Since I need the output to not have a header, I want to have one file (as defined by schema.ini) that I will temporarily write the data into then copy and rename it before starting again. Using VS2017, when I debug it spits out the error that it cannot find RawC.txt after the first iteration. I cannot seem to figure out why. It is probably something simple but I have been unable to locate online. Can anyone help me out here? Below is the block I am having trouble with:

For each of the three files, output the sorted list. Schema has the correct format

 For index = 0 To 2
       If index = 0 Then
          whicharr = arrSt(1)
       ElseIf index = 1 Then
          whicharr = arrSe(1)
       ElseIf index = 2 Then
          whicharr = arrVi(1)
       End If
       stopFile = "SELECT " & complist(index) & " INTO [Text;Database=" & TMPath & "].[RawC.txt] FROM [" & whicharr & "] ORDER BY " & complist(index)
       cmd = New OleDbCommand(stopFile, conn)
       cmd.ExecuteNonQuery()
       'Now Copy and rename this file
       My.Computer.FileSystem.CopyFile(TMPath & "\RawC.txt", TMPath & "\" & whicharr & ".txt")
       'And delete the old RawC.txt file
       My.Computer.FileSystem.DeleteFile(TMPath & "\RawC.txt")
 Next

The final output from this loop should be three unique files that I will pass to another code that will perform some math on it.

0

There are 0 best solutions below