cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Passing Multiple Values from Listbox one at a time to SQL

Hi all,

 

I've got a list box which lists food items such as "Milk", "Cheese" etc (about 20 items)

 

In a SQL table I have 3 columns, the food name, the shop and the price. I want it so that when users pick any number of the food items from the list box, then hit a button it sends each of the selected values through as seperate rows to the SQL table.

 

I've tried just picking out the 'Selected' and it only ever passes through the item which is selected lowest in the list. If I use a 'forall' it will add the number of rows I need, but repeat the same food item for each one as opposed to all of the selected items.

 

I've also tried a flow but no luck - I'm struggling to find the syntax to say "Pass through the selected values each on their own row"

 

Any help?

1 ACCEPTED SOLUTION

Accepted Solutions
v-micsh-msft
Community Support
Community Support

Hi @thewake,

 

Could you please share more information about the source of the ListBox control?

and Which data do you want to be stored in the SQL Table?

Further, could you please also share a reference of the forall formula?

Also, please make sure you have the ListBox MultiSelection (SelectMultiple  property) enabled.

If you would like to save the selected items in ListBox to the food name column of the SQL table, then the formula of OnSelect property of a Button control should be as below:

ForAll(ListBox1.SelectedItems.Value,Patch('[dbo].[Foods]',Defaults('[dbo].[Foods]'),{foodName:Value})))

Note: ‘[dbo].[Foods]’ is a SQL table. The Value in above formula represents the each item of selected items of ListBox control.

 

Adding some reference:

ListBox control in PowerApps

Forall function in PowerApps

 

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
BitLord69
Power Participant
Power Participant

Have a look at this post: https://powerusers.microsoft.com/t5/PowerApps-Forum/Listbox-MultiSelect-Values/td-p/17709

 

Can you show your code that dosen't work?

v-micsh-msft
Community Support
Community Support

Hi @thewake,

 

Could you please share more information about the source of the ListBox control?

and Which data do you want to be stored in the SQL Table?

Further, could you please also share a reference of the forall formula?

Also, please make sure you have the ListBox MultiSelection (SelectMultiple  property) enabled.

If you would like to save the selected items in ListBox to the food name column of the SQL table, then the formula of OnSelect property of a Button control should be as below:

ForAll(ListBox1.SelectedItems.Value,Patch('[dbo].[Foods]',Defaults('[dbo].[Foods]'),{foodName:Value})))

Note: ‘[dbo].[Foods]’ is a SQL table. The Value in above formula represents the each item of selected items of ListBox control.

 

Adding some reference:

ListBox control in PowerApps

Forall function in PowerApps

 

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

That worked perfectly. I just didn't have the syntax right. Thanks for the example

@v-micsh-msft

 

LISTBOX DEFAULT SELECT ALL

 

ComboBox with multi select

ItemsDistinct(Filter(Product,Name.Id=Dropdown.Selected.ID),Title)

ListBox

Items: Distinct(Filter(product,Title in Listbox.SelectedItems),Description)

Default:LookUp(Product,Title in listbox.SelectedItems.Result,Description)

textInput: Concat(ADDescription.SelectedItems,Result&",")

 

while using this scenario, Its working when there is only one item in the combobox and if we select it the description is selected default and added to the textbox

But, when we select multiple items in the combobox, on description it shows both descriptions are selected but its only populating one description on top of the list.

Can you help me with were i'm messing with the formula.

Thanks in advance.

MK

LISTBOX DEFAULT SELECT ALL

 

ComboBox with multi select

ItemsDistinct(Filter(Product,Name.Id=Dropdown.Selected.ID),Title)

ListBox

Items: Distinct(Filter(product,Title in Listbox.SelectedItems),Description)

Default:LookUp(Product,Title in listbox.SelectedItems.Result,Description)

textInput: Concat(ADDescription.SelectedItems,Result&",")

 

while using this scenario, Its working when there is only one item in the combobox and if we select it the description is selected default and added to the textbox

But, when we select multiple items in the combobox, on description it shows both descriptions are selected but its only populating one description on top of the list.

Can you help me with were i'm messing with the formula.

Thanks in advance.

MK

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,559)