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:

Code: Copy
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)
 
In the line: ListOfMaps.add(M) you add M; where does it come from? Maybe you should add Names?
Greetings
Reinhard
 
Upvote 0
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
You need to Dim a new instance of M every time round the loop:

Code: Copy
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
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

Code: Copy
If Cursor.RowCount-1>0 Then
instead of
If Cursor.RowCount>0 Then
 
Upvote 0
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
Back
Top