# Can SQLiteDatabase.SelectSQL accept an array as parameter?

**URL:** <https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446>\
**Category:** Databases\
**Created:** [November 3, 2021, 8:29pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446 "2021-11-03T20:29:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Sun](https://forum.xojo.com/user_avatar/forum.xojo.com/frank_sun/32/1482_2.png) [@Frank\_Sun](https://forum.xojo.com/u/Frank_Sun)\
**Post date:** [November 3, 2021, 8:29pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/1 "2021-11-03T20:29:38Z")

</div>

Hi,

I just ran into this runtime error:

> parameters cannot be arrays

which was generated by this line of code:

```auto
rs = MainDatabase.SelectSQL(sql, values)

```

where values() is a string array. I thought I was being smart because the SQL select statement will vary in the number of parameters it needs and rather than writing multiple individual SelectSQL statements with ParamArray of different lengths, this looked much neater.

I thought this was ok, based on the Language Reference:

**[Database](https://documentation.xojo.com/api/databases/database.html_Class).SelectSQL** (SQLStatement as [String](https://documentation.xojo.com/api/data_types/string.html) [,[ParamArray](https://documentation.xojo.com/api/language/paramarray.html) values() as [Variant](https://documentation.xojo.com/api/data_types/variant.html)]) **As** [RowSet](https://documentation.xojo.com/api/databases/rowset.html)  
**[Database](https://documentation.xojo.com/api/databases/database.html_Class).SelectSQL** (SQLStatement as [String](https://documentation.xojo.com/api/data_types/string.html) [,values() as [Variant](https://documentation.xojo.com/api/data_types/variant.html)]) **As** [RowSet](https://documentation.xojo.com/api/databases/rowset.html)

My interpretation was that you could pass either an indefinite number of parameters separately or one array that contained all the parameters.

Then I thought maybe the problem was that my values() array was of type String, not Variant, so I changed it, but then got a different runtime error:

> Expected 2 parameters to be bound but received 1

I guess it then treated my passed array as just the first parameter.

I can easily work around this by just writing out separate statements for different conditions, but could someone clarify for me what the actual situation is please? What does the Language Reference mean by the second version then?

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [November 3, 2021, 8:38pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/2 "2021-11-03T20:38:48Z")

</div>

I’ve used variant arrays to pass the values for an API 2.0 prepared sql statement. Are you sure your array length matches the number of placeholders in the SQL?

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [November 3, 2021, 8:40pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/3 "2021-11-03T20:40:38Z")

</div>

It has to be a Variant array, not a String array, is my best guess.

---

<div class="post-metadata">

**Author:** ![Anthony\_Dellos](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_dellos/32/208_2.png) [@Anthony\_Dellos](https://forum.xojo.com/u/Anthony_Dellos)\
**Post date:** [November 3, 2021, 8:43pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/4 "2021-11-03T20:43:26Z")

</div>

> [@Tim\_Parnell](#):
>
> Are you sure your array length matches the number of placeholders in the SQL?

**This.**

The error:

> Expected 2 parameters to be bound but received 1

sure _sounds like_ you have a mismatch in the number of placeholders in your SQL string vs. the number of values in the passed array.

Sample code from the LR:

```auto
Var rowsFound As RowSet
rowsFound = db.SelectSQL("SELECT * FROM Customer WHERE Age=? AND PostalCode=?", Age.Value, PostalCode.Value)

```

The Number of “?” symbols in the SQL needs to match the number of array values. If it does, then maybe what Kem suggested, otherwise it _might_ be a bug?

---

<div class="post-metadata">

**Author:** ![Frank\_Sun](https://forum.xojo.com/user_avatar/forum.xojo.com/frank_sun/32/1482_2.png) [@Frank\_Sun](https://forum.xojo.com/u/Frank_Sun)\
**Post date:** [November 3, 2021, 8:44pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/5 "2021-11-03T20:44:26Z")

</div>

Hi Tim,

You are spot on. This is embarrassing! I missed adding one of the arguments to my values array! Now corrected and works fine 😚

Thanks guys

---

<div class="post-metadata">

**Author:** ![Anthony\_Dellos](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_dellos/32/208_2.png) [@Anthony\_Dellos](https://forum.xojo.com/u/Anthony_Dellos)\
**Post date:** [November 3, 2021, 8:45pm UTC](https://forum.xojo.com/t/can-sqlitedatabase-selectsql-accept-an-array-as-parameter/66446/6 "2021-11-03T20:45:14Z")

</div>

(and yes, the sample code isn’t using an array, it was just an easy way to show some SQL with the correct “?” “value identifiers”.)

LR entry is here: [https://documentation.xojo.com/api/databases/database.html#database-selectsql](https://documentation.xojo.com/api/databases/database.html#database-selectsql)

[edit: fixed link]
