I have the following code to export a table to a csv file. Surely there is a better method than this?
Does anyone have a code snippet?
Does anyone have a code snippet?
B4X:
Dim List1 As List
Dim Qry As String
Dim TextWriter1 As TextWriter
Qry="Select * from Orders order by Date,CustCode"
Cursor1=SQL.ExecQuery(Qry)
If Cursor1.RowCount=0 Then
Cursor1.Close
Return
End If
TextWriter1.Initialize(File.OpenOutput(File.DirDefaultExternal, "Orders.csv", False))
For i = 0 To Cursor1.RowCount-1
Cursor1.Position=i
Datex = Cursor1.GetString("Date")
CC = Cursor1.GetString("CustCode")
Pc = Cursor1.GetString("ProdCode")
Qty = Cursor1.GetInt("Qty")
Cost = Cursor1.GetInt("Cost")
Sent = Cursor1.GetInt("Sent")
TextWriter1.Write(Datex & "," & CC & "," & PC & "," & Qty & "," & Cost & "," & Sent & Chr(13) & Chr(10))
Next
TextWriter1.Flush
TextWriter1.Close
Cursor1.Close