Can anyone see what i am doing wrong here. When i read the record back i do not get any items in the columns even though when i check the listofmaps all looks ok?
:BangHead:
B4X:
Names.Initialize
Names.AddAll(Array As String("Company","Contact","Street","Suburb","Postcode","City","email","Phone","Mob","UserName","UserEmail"))
For i = 0 To pnlRego.NumberOfViews-1
If pnlRego.GetView(i) Is EditText Then
Dim ET As EditText = pnlRego.GetView(i)
If ET.Text="" Then
.....
End If
M.Put(Names.Get(i), ET.Text)
Log(Names.Get(i) & " " & ET.Text)
End If
Next
ListOfMaps.Add(M)
DBUtils.InsertMaps(Main.SQL,"Table", ListOfMaps)
You need to Dim a new instance of M every time round the loop:
B4X:
For i = 0 To pnlRego.NumberOfViews-1
If pnlRego.GetView(i) Is EditText Then
Dim ET As EditText = pnlRego.GetView(i)
If ET.Text="" Then
.....
End If
Dim M As Map 'Add these two lines
M.Initialize '
M.Put(Names.Get(i), ET.Text)
Log(Names.Get(i) & " " & ET.Text)
ListOfMaps.Add(M) ' And Move this one to inside the loop
End If
Next
And add it to the list within the loop too.
If you are still not getting any records added, check that the column names in Names correspond to the fields in the table.
For some reason it is working without having to use the Dim statement within the loop. The code was correct all the time. My error was when reading the record back to check i had the line
B4X:
If Cursor.RowCount-1>0 Then
instead of
If Cursor.RowCount>0 Then