web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to update Gallery ...
Power Apps
Answered

How to update Gallery edits connected to SQL table?

(0) ShareShare
ReportReport
Posted on by 15

I am currently creating a PowerApp with the data source being a SQL table. I am using a gallery to display all the data in the table with the option for the user to edit the table values and a save button beside each of the rows to save the data. However, I am having trouble figuring the correct logic/code for the save buttons so that the user can update the data directly into SQL. How would I go about doing this? Thanks in advance! 

Screenshot 2021-01-27 094121.png
Categories:
  • Verified answer
    timl Profile Picture
    37,424 Super User 2026 Season 2 on at

    Hi @overhead_press 

    You would call the Patch function to do this. There are more details in the documentation here.

    https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-patch

     

    The OnSelect formula for your button would look like this.

    Patch(
     [dbo].[YourTable],
     ThisItem,
     {
     yourNumericField: Value(yourTextInputControl.Text)
     }
    )

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @overhead_press 

    Assuming you wish to submit your changes to your table directly from the gallery.  You would put Input controls on the gallery with the default set to the fields you want to change.  So for a date, put a datepicker control.  For a Text type column, put on a TextInput box. ,  etc.  In your save icon OnSelect property, put 

     

    Patch(yourDBO, ThisItem, {yourdate:Datepicker1.SelectedDate, yourtext: TextInputBox1.Text, etc.})

     

    _1.pngIn the example I used a datasource called Orders and put in some controls with their Defaults set to ThisItem.'Payment Type' fpr tje radio control, ThisItem.'Total Fee' for the slider  and ThisItem.'Order Date' for the datepicker.

  • overhead_press Profile Picture
    15 on at

    Thanks for the reply, where would I specify the primary keys in the function that would connect the tables? 

  • overhead_press Profile Picture
    15 on at

    Thanks for the reply, where doI specify the primary keys in the function that would connect the tables? 

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @overhead_press 

    I'm not sure I understand your issue.  SQL automatically assigns a primary key to every record created.  If your data is in a gallery, it already must have a primary key.  

  • Verified answer
    timl Profile Picture
    37,424 Super User 2026 Season 2 on at

    Hi @overhead_press 

    When you call the Patch function like so, ThisItem provides a reference to the row in the the gallery that you want to update.

     

    Patch(
     [dbo].[YourTable],
     ThisItem,
     {
     yourNumericField: Value(yourTextInputControl.Text)
     }
    )

    There is no need to specifically pass the primary key value that corresponds to the record that you want to update when you call the Patch function.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 221 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 120

Last 30 days Overall leaderboard