adding record incorrectly using maps

Smee

Well-Known Member
Licensed User
Longtime User
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)
 

rboeck

Well-Known Member
Licensed User
Longtime User
In the line: ListOfMaps.add(M) you add M; where does it come from? Maybe you should add Names?
Greetings
Reinhard
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Hi
Thanks for the reply,

It turns out the code is correct. The error was elsewhere when i was reading the items back

:sign0013:
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
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.
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Thanks for the reply Steve,

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
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes of course, as it's all one record, sorry, my mistake.

I would consider putting the Field Names in the EditText's Tags though, in case you edit the layout and it changes the order.
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
I would consider putting the Field Names in the EditText's Tags though, in case you edit the layout and it changes the order.


I wish i had thought of that BEFORE i changed the layout
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…