cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kldmurshed
Helper I
Helper I

Help for updating SQL table from selected list items

Hi,

How can I update the SQL table below with these selected list values after pressing the submit button?

 

Kldmurshed_2-1600807946924.png

 

Kldmurshed_1-1600807906673.png

Values will be:

MaterialStaus      InspID

-------------------------

      1                      201

      1                      201

      1                      201

 

I spend 4 hours trying to figure out how to solve it.

I've tried ForAll but it keeps creating new records.

 

Your help would be appreciated.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PaulD1
Community Champion
Community Champion

I believe the code would be something like the following:

 

ForAll(RenameColumns(ListBox2.SelectedItems,"SerialNumber","SelectedSerialNumber") ,
Patch(MyTable,LookUp(MyTable, SerialNumber = SelectedSerialNumber,
{
MaterialStatus: ddSelectMaterial.Selected.MaterialStatus,
InspID: ddSelectInspector.Selected.InspID
})
)

 

Note that I've used RenameColumns to try to disambiguate between the SerialNumber field name in the table and the SerialNumber in the listbox2 selection.

I've used Patch instead of UpdateIf as UpdateIf is not delegable so is no good if the number of rows in the table exceeds the delegation limit.

View solution in original post

5 REPLIES 5
VijayTailor
Resident Rockstar
Resident Rockstar

Hi,

You can use LIke below.
UpdateIf(Inventory, ProductName = ProductGallery.Selected.ProductName, {UnitsInStock:UnitsInStock-UnitsSold.Value}).

For More Details, Plz find the below URL.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-update-updateif

Hope this will help you to resolve your Issue.

mdevaney
Super User
Super User

@Kldmurshed 

You must use a ComboBox control instead of a Listbox control.  Why?  ListBoxes cannot output multiple selections.  Its really dumb because the user can click multiple selections.  However, Power Apps cannot tell which selections are clicked when there are more than one.  Its a useless control in my humble opinion.

 

From the Official MS documentation
Selected – The data record that represents the selected item. You can only have one default selected item. If you need multiple selected items please use the Combo Box control.

 

 

MS Official Docs on ListBoxes

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-list-box

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@VijayTailor 

Have you responded to the wrong question?  I do not see any of the column names in your code here...

@mdevaney 

 

The list box can actually works as combo box.

I made a simple test to output the selected items, see the example bleow.

I used flowing code to output the selections: Concat(ListBox2.SelectedItems,SerialNumber,",")

Lets say its a combo, how and whats the code to update the database table

 

 

 

 

Kldmurshed_0-1600824644023.png

 

PaulD1
Community Champion
Community Champion

I believe the code would be something like the following:

 

ForAll(RenameColumns(ListBox2.SelectedItems,"SerialNumber","SelectedSerialNumber") ,
Patch(MyTable,LookUp(MyTable, SerialNumber = SelectedSerialNumber,
{
MaterialStatus: ddSelectMaterial.Selected.MaterialStatus,
InspID: ddSelectInspector.Selected.InspID
})
)

 

Note that I've used RenameColumns to try to disambiguate between the SerialNumber field name in the table and the SerialNumber in the listbox2 selection.

I've used Patch instead of UpdateIf as UpdateIf is not delegable so is no good if the number of rows in the table exceeds the delegation limit.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

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

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,365)