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!
Solved! Go to Solution.
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)
}
)
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.
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)
}
)
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.})
In 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?
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.
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.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
187 | |
53 | |
52 | |
38 | |
37 |
User | Count |
---|---|
282 | |
97 | |
86 | |
80 | |
77 |