cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
overhead_press
New Member

How to update Gallery edits connected to SQL table?

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! 

2 ACCEPTED SOLUTIONS

Accepted Solutions
timl
Super User
Super User

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)
          }
)

 

View solution in original post

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.

 

View solution in original post

6 REPLIES 6
timl
Super User
Super User

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
Super User
Super User

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.

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

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

Drrickryp
Super User
Super User

@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.  

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.

 

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.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,482)