I am sorry if this question is a repeat. I have a system.object variable where I store results for a select query. I need to output the results to a flat file to further process it. I have the following piece of code that works for couple of seconds and then throws the system invocation error. Can you please suggest any edits to this or if I am doing something wrong:
Public Sub Main()
Dim x As New OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim str As String = vbNullString
If System.IO.File.Exists("D:\BKP\AD.txt") = False Then
System.IO.File.Create("D:\BKP\AD.txt")
End If
'MessageBox.Show("Hello")
Dim i As Int32
x.Fill(dt, Dts.Variables("User::LDAPResultSet").Value)
i = dt.Rows.Count
For j As Int32 = 0 To i - 1
str = str & Join(dt.Rows.Item(j).ItemArray(), ",") & vbCrLf
Next
Dim objWriter As New System.IO.StreamWriter("D:\BKP\AD.txt")
objWriter.Write(str)
objWriter.Close()
End Sub
End Class
Is there a better way to write this or if there's an alternative code piece I'd like to try that as well. Thank you for your time.