Hi
I need help please.
I can load a CSV File, but when I want to read the file and save it in a SQLite Database, it tells me that the file does not exit.
Any ideas please?
I need help please.
I can load a CSV File, but when I want to read the file and save it in a SQLite Database, it tells me that the file does not exit.
Any ideas please?
Read CSV File:
[/
Sub Import_Coords
Dim fd As FileDialog
fd.FilePath = File.DirRootExternal
fd.TextColor=Colors.Black
fd.FileFilter=".csv,.txt"
fd.ScrollingBackgroundColor=Colors.Gray
Dim sf As Object = fd.ShowAsync("Select File", "Import", "Cancel", "", Null, False)
Wait For (sf) Dialog_Result(Result As Int)
If Result = DialogResponse.POSITIVE Then
Log("File path: " & fd.FilePath)
Log("File name: " & fd.ChosenName)
SaveFile(fd.FilePath, fd.ChosenName)
End If
End Sub
Sub SaveFile(A As String, B As String)
Dim FileName As String
Dim lst1 As List
FileName= A & "/" & B
Try
lst1.Initialize
CGlobals.SQL1.BeginTransaction
lst1 = SU.LoadCSV(File.DirRootExternal, FileName, ",")
For i = 0 To lst1.Size - 1
Dim sColumn() As String
sColumn = lst1.Get(i)
If CGlobals.CoordCode=1 Then
'Site Coords
CGlobals.SQL1.ExecNonQuery2("INSERT INTO SCoords VALUES (a,b,c,d,e) VALUES (?, ?, ?, ?, ?)", sColumn)
else if CGlobals.CoordCode=2 Then
'Global Coords
CGlobals.SQL1.ExecNonQuery2("INSERT INTO GCoords VALUES (a,b,c,d,e) VALUES (?, ?, ?, ?, ?)", sColumn)
Else
'Job Coords
CGlobals.SQL1.ExecNonQuery2("INSERT INTO Coords VALUES (a,b,c,d,e) VALUES (?, ?, ?, ?, ?)", sColumn)
End If
Next
CGlobals.SQL1.TransactionSuccessful
Catch
Log(LastException.Message)
End Try
' Dim SU As StringUtils
' Dim Table As List
' Table = SU.LoadCSV(File.DirRootExternal, FileName, ",")
' Dim Table2 As List
' Dim Items() As String
' Table2.Initialize
' For i = 0 To Table.Size - 1
' Items = Table.Get(i)
' Dim m As Map
' m.Initialize
' m.Put("column 1", Items(0)) 'You will need to replace the columns names with the correct names
' m.Put("column 2", Items(1))
' Table2.Add(m)
' Next
'
' DBUtils.InsertMaps(CGlobals.SQL1, "YourTable", Table2)
CGlobals.SQL1.EndTransaction
Msgbox2Async("Points Imported", "Imported", "OK", "", "", Null,False)
Wait For Msgbox_Result (Answ As Int)
End Sub
]