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

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,757)