# Filling a popup menu with rows error

**URL:** <https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172>\
**Category:** macOS\
**Created:** [November 13, 2022, 12:44pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172 "2022-11-13T12:44:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![André\_van\_Haren](https://forum.xojo.com/user_avatar/forum.xojo.com/andr%C3%A9_van_haren/32/1980_2.png) [@André\_van\_Haren](https://forum.xojo.com/u/Andr%C3%A9_van_Haren)\
**Post date:** [November 13, 2022, 12:44pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/1 "2022-11-13T12:44:23Z")

</div>

I am trying to place the values of a sqlite table column in a popup menu, but keep getting a syntax error. What am I doing wrong here?

```auto
var rs as Rowset
rs = app.db.SelectSQL("SELECT * FROM Stories ORDER BY Story_Title") // Get all the data from the Stories table.
if rs <> Nil then
  For i As Integer = 1 To rs.RowCount
    PopStoryID.AddRow.(rs.Column("Story_Title").StringValue )
    rs.MoveToNextRow
  Next
  rs.Close
end If

```

 ![Screenshot 2022-11-13 at 13.45.06](https://forum.xojo.com/uploads/default/original/2X/3/35d6f051988ae69c7e612f25bf4ffdd7463ed995.png)

---

<div class="post-metadata">

**Author:** ![Thomas\_Roemert](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_roemert/32/827_2.png) [@Thomas\_Roemert](https://forum.xojo.com/u/Thomas_Roemert)\
**Post date:** [November 13, 2022, 12:51pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/2 "2022-11-13T12:51:58Z")

</div>

Remove the point behind AddRow

---

<div class="post-metadata">

**Author:** ![PaulS](https://forum.xojo.com/user_avatar/forum.xojo.com/pauls/32/199_2.png) [@PaulS](https://forum.xojo.com/u/PaulS)\
**Post date:** [November 13, 2022, 12:54pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/3 "2022-11-13T12:54:03Z")

</div>

```auto
PopStoryID.AddRow rs.Column("Story_Title").StringValue

```

---

<div class="post-metadata">

**Author:** ![André\_van\_Haren](https://forum.xojo.com/user_avatar/forum.xojo.com/andr%C3%A9_van_haren/32/1980_2.png) [@André\_van\_Haren](https://forum.xojo.com/u/Andr%C3%A9_van_Haren)\
**Post date:** [November 13, 2022, 2:09pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/4 "2022-11-13T14:09:57Z")

</div>

Thanks, that part was indeed an error. However now I am getting another one:

![Screenshot 2022-11-13 at 15.07.26](https://forum.xojo.com/uploads/default/original/2X/9/93324f5688d5615f28fcfbe39e4e67abca744b9c.png)

probably not related to the period. I will study this more in depth later.

---

<div class="post-metadata">

**Author:** ![André\_van\_Haren](https://forum.xojo.com/user_avatar/forum.xojo.com/andr%C3%A9_van_haren/32/1980_2.png) [@André\_van\_Haren](https://forum.xojo.com/u/Andr%C3%A9_van_Haren)\
**Post date:** [November 14, 2022, 6:57am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/5 "2022-11-14T06:57:50Z")

</div>

Thanks, I got this error fixed. The next step is now to ONLY see characters of a story in the Character listbox when that Story title is choosen from a drop down menu. For this I am comparing the SelectedRowValue of the drop down menu with contain the Story titles with the Story Title column in the database, but I am getting a syntax error. It does work when I type the story title in the code directly, so I know this works, but when I try to get the title value directly from the drop down value, I see this error:

![Screenshot 2022-11-14 at 07.51.27](https://forum.xojo.com/uploads/default/original/2X/4/48dc022b4d70e02fd47e8f32d9b6f48fd58b0053.png)

`rs = app.DB.SelectSQL("SELECT * FROM CHARACTERS INNER JOIN STORIES on CHARACTERS.fkstory = STORIES.id where STORIES.Story_Title = " + PopStoryID.SelectedRowValue )`

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [November 14, 2022, 7:16am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/6 "2022-11-14T07:16:22Z")

</div>

Have a look at the SQL that is causing the error. After “Wars” you have a bracket “(”. You need to put quotes around PopStoryID.SelectedRowValue.

You probably shouldn’t use string values. Save a RowID or identifier and use that instead.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [November 14, 2022, 7:20am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/7 "2022-11-14T07:20:04Z")

</div>

like Beatrix said: don’t use string values to compare in an sql query.  
use integer unique ID  
what happens if two movies have the same name ? this happens …

---

<div class="post-metadata">

**Author:** ![Scott\_Griffitts](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@Scott\_Griffitts](https://forum.xojo.com/u/Scott_Griffitts)\
**Post date:** [November 14, 2022, 7:24am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/8 "2022-11-14T07:24:26Z")

</div>

You’re not enclosing the STORIES.Story\_Title in single quotes, hence the syntax error. A more conventional approach would be to use STORIES.id for your lookup. (What if you have more than one story with the same title?) You could store the ID in the rowtag of the popupmenu.

Either way you should be using parameters for your SQL. It will take care of the single quotes for you, as well as escaping single quotes in the string, and will also help prevent SQL injection attacks.

Check out [https://documentation.xojo.com/api/databases/database.html#database-selectsql](https://documentation.xojo.com/api/databases/database.html#database-selectsql) and [https://documentation.xojo.com/api/databases/database.html#database-executesql](https://documentation.xojo.com/api/databases/database.html#database-executesql) and take note of the parts about passing values as parameters.

---

<div class="post-metadata">

**Author:** ![Scott\_Griffitts](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@Scott\_Griffitts](https://forum.xojo.com/u/Scott_Griffitts)\
**Post date:** [November 14, 2022, 7:26am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/9 "2022-11-14T07:26:47Z")

</div>

You guys beat me to it.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [November 14, 2022, 8:42am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/10 "2022-11-14T08:42:00Z")

</div>

> [@André\_van\_Haren](#):
>
> rs = app.DB.SelectSQL("SELECT \* FROM CHARACTERS INNER JOIN STORIES on CHARACTERS.fkstory = STORIES.id where STORIES.Story\_Title = " + PopStoryID.SelectedRowValue )

```auto
... PopStoryID.SelectedRowValue.ToString

```

---

<div class="post-metadata">

**Author:** ![André\_van\_Haren](https://forum.xojo.com/user_avatar/forum.xojo.com/andr%C3%A9_van_haren/32/1980_2.png) [@André\_van\_Haren](https://forum.xojo.com/u/Andr%C3%A9_van_Haren)\
**Post date:** [November 14, 2022, 11:09am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/11 "2022-11-14T11:09:52Z")

</div>

Even with titles without a bracket, I get this error:

![Screenshot 2022-11-14 at 12.03.12](https://forum.xojo.com/uploads/default/original/2X/6/6946646fc4a9c288c53e41b90510e88cc772b1b4.png)

Placing quotes around the code didn’t solve it. I agree though that I should use the story.id value from the db and not the story title to compare with the drop down menu, but I don’t understand how to do this. When I place the story id in the drop down menu (so no title to see), the correct story characters are showing in the listbox, but then it’s not possible to know which stories are available in the drop down menu.

![Screenshot 2022-11-14 at 12.08.40](https://forum.xojo.com/uploads/default/original/2X/3/3b56423b92761c829e3029d06f45ddba7272ef3e.png)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [November 14, 2022, 11:24am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/12 "2022-11-14T11:24:14Z")

</div>

store the story.id in the rowtag of the popup menu

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [November 14, 2022, 11:40am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/13 "2022-11-14T11:40:37Z")

</div>

Have a look at the SQL in the debugger and then you will see the problem with the SQL. Your code for the listbox should look like this:

```auto
loop over the rows in the rowset
   listbox.add(rowset(story))
   listbox.rowtag(listbox.LastAddedRowIndex) = rowset(rowid)
next

```

---

<div class="post-metadata">

**Author:** ![Thomas\_Roemert](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_roemert/32/827_2.png) [@Thomas\_Roemert](https://forum.xojo.com/u/Thomas_Roemert)\
**Post date:** [November 14, 2022, 11:52am UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/14 "2022-11-14T11:52:49Z")

</div>

To populate your popupmenu:

```auto
var rs as Rowset
rs = app.db.SelectSQL("SELECT * FROM Stories ORDER BY Story_Title") // Get all the data from the Stories table.
if rs <> Nil then
  For i As Integer = 1 To rs.RowCount
    PopStoryID.AddRow ( rs.Column("Story_Title").StringValue )
	PopStoryID.RowTagAt ( i - 1 ) = rs.Column("STORIES.id").IntegerValue // DesktopPopupmenu is zero-based
    rs.MoveToNextRow
  Next
  rs.Close
end If

```

To get the rowtag:

```auto
Var myTag as Integer
...
myTag = PopStoryID.RowTagAt ( PopStoryID.SelectedRowIndex )

```

---

<div class="post-metadata">

**Author:** ![André\_van\_Haren](https://forum.xojo.com/user_avatar/forum.xojo.com/andr%C3%A9_van_haren/32/1980_2.png) [@André\_van\_Haren](https://forum.xojo.com/u/Andr%C3%A9_van_Haren)\
**Post date:** [November 14, 2022, 12:19pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/15 "2022-11-14T12:19:06Z")

</div>

Thanks so much, Thomas. I am still trying to get my head around how to use row tags, but I believe I start to understand the idea now. You connect it to a row simply by adding “.RowTageAt” to the listbox and the value is added by whatever is place after the “=” sign?  
Not that difficult now I see the structure 🙂

Using your code makes the compiled app crash, but I need to play around with the code some more to see what is happening. Thanks!

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [November 14, 2022, 1:59pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/16 "2022-11-14T13:59:46Z")

</div>

The rowtag takes a Variant so if you need to store multiple values in the rowtag, make a class with those properties and put an instance of the class in the rowtag.

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [November 14, 2022, 5:39pm UTC](https://forum.xojo.com/t/filling-a-popup-menu-with-rows-error/73172/17 "2022-11-14T17:39:42Z")

</div>

You can think of the RowTag as a hidden column on the listbox. It can hold a Variant, so it can hold data of just about any data type. There are CellTags, CellTagAt(Row, Column), as well if you needed to hold further non-displayed information.
