U
Usarian Skiff
I'm making a csv file from a datatable. Here's my code
'Copy Headers
Dim obj(8) As Object
Dim txt As String
obj = dt.DefaultView.Item(0).Row.ItemArray
txt = Join(obj, ",")
filedata = txt
'Copy Data
For x = 0 To dt.DefaultView.Count - 1
filedata &= vbCrLf
obj = dt.DefaultView.Item(x).Row.ItemArray
txt = String.Format(",", obj)
filedata &= txt
Next
'Write File
Try
Dim savecsv As New StreamWriter(filename)
savecsv.Write(filedata)
savecsv.Close()
Catch ex As Exception
errormsg = ex.ToString
abort = True
End Try
I found that passing the datarow as an array into an array object will convert into a string using String.Join() to add in commas where apropriate. It works in the Headers section, but not in the Copy Data section. I get an error stating that I can't convert an array object into a string. Any tricks?
Usarian
'Copy Headers
Dim obj(8) As Object
Dim txt As String
obj = dt.DefaultView.Item(0).Row.ItemArray
txt = Join(obj, ",")
filedata = txt
'Copy Data
For x = 0 To dt.DefaultView.Count - 1
filedata &= vbCrLf
obj = dt.DefaultView.Item(x).Row.ItemArray
txt = String.Format(",", obj)
filedata &= txt
Next
'Write File
Try
Dim savecsv As New StreamWriter(filename)
savecsv.Write(filedata)
savecsv.Close()
Catch ex As Exception
errormsg = ex.ToString
abort = True
End Try
I found that passing the datarow as an array into an array object will convert into a string using String.Join() to add in commas where apropriate. It works in the Headers section, but not in the Copy Data section. I get an error stating that I can't convert an array object into a string. Any tricks?
Usarian