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 / Issue updating multipl...
Power Apps
Suggested Answer

Issue updating multiple gallery items to SQL in Power Apps

(0) ShareShare
ReportReport
Posted on by 19
Hi All,

I’ve been stuck on this for the past seven days and would really appreciate your help.

I need to update multiple rows in a SQL table directly from a Power Apps gallery. Each gallery item contains three ComboBox controls and three TextInput controls. I’m looking for the correct approach (and formula) to save all edited items in the gallery back to SQL in one go.

 
App Onstart:
 
ClearCollect(colAllChannel,'GPS.sql_channel');
 
 
Gallery items:
 
colAllChannel
 
My button onselect:
ForAll(
    colAllChannel As r,
    Patch(
        'GPS.sql_channel',
        LookUp('GPS.sql_channel', ID = r.ID),
        {
            Textinput 1: Value(r.Textinput 1),
            Textinput 2:Value(r.Textinput 2)  
         
        }
    )
)   // here ID is primary key
  
I’m trying to update multiple rows in SQL from my Power Apps gallery, but none of the rows are getting updated. I keep getting an error, and I can’t figure out why. Could someone please help me understand what might be causing this?
 
Please provide correct code. Thanks for your help
Categories:
I have the same question (2)
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @HK-21101814-0
     
    Please try below code: 

    If your SQL column name contains spaces, make sure to wrap it in single quotes while patching.

    ForAll(
        colAllChannel As r,
        Patch(
            'GPS.sql_channel',
            LookUp('GPS.sql_channel', ID = r.ID),
            {
                'Textinput 1': Value(r.'Textinput 1'),
                'Textinput 2':Value(r.'Textinput 2')  
             
            }
        )
    )

    If the above solution still doesn’t work, please share a screenshot of your collection output, your SQL table structure, and the exact error message you are getting.

    That information will help us troubleshoot the issue further and give you a more accurate solution.

    Hope this helps 👍

    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!

     

  • HK-21101814-0 Profile Picture
    19 on at
    Hi @Kalathiya actually SQL column and textinput names are correct. For your reference I just provided in that way. Could you please give me the correct code please. Actually the logic may be incorrect
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    @HK-21101814-0,  

    It looks like the logic is correct. However, when using a SQL data source, make sure the table has a primary column. otherwise, Power Apps won’t support write operations like Patch/update.

     
    If you are creating new record then your syntax will be: 
    ForAll(
        colAllChannel As r,
        Patch(
            'GPS.sql_channel',
            Defaults('GPS.sql_channel'),
            {
                'Textinput 1': Value(r.'Textinput 1'),
                'Textinput 2':Value(r.'Textinput 2')  
             
            }
        )
    )
    If you are updating the record then:
    ForAll(
        colAllChannel As r,
        Patch(
            'GPS.sql_channel',
            LookUp('GPS.sql_channel', ID = r.ID),
            {
                'Textinput 1': Value(r.'Textinput 1'),
                'Textinput 2':Value(r.'Textinput 2')  
             
            }
        )
    )
     
    If you are still facing an error, Please share the error details.
     
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
     
  • HK-21101814-0 Profile Picture
    19 on at
    @Kalathiya I guess thats not an issue. I am pasting my original code here please check
    ForAll(
        colAllChannel As r,
        Patch(
            'GPS.fct_tapp_wip_channel',
            LookUp('GPS.fct_tapp_wip_channel', ID = r.ID),
            {
                Tgt_TDP: Value(r.Tgt_TDP),
                Tgt_HEL:Value(r.Tgt_HEL)  
             
            }
        )
    )
     
    column doesnt contain spaces. But this method is not working as expected
  • Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @HK-21101814-0

    Please note that these two columns are Number columns only, so the code looks correct.

    Could you please share the error screenshot? That will help us troubleshoot the issue and provide an appropriate solution.

     
  • HK-21101814-0 Profile Picture
    19 on at
     Hi @Kalathiya 
    ForAll(
        colAllChannel As r,
        Patch(
            'GPS.fct_tapp_wip_channel',
            LookUp('GPS.fct_tapp_wip_channel', ID = r.ID),
            {
                Tgt_TDP: Value(r.Tgt_TDP),
                Tgt_HEL:Value(r.Tgt_HEL)  
             
            }
        )
     
    now I am not getting any error but gallery values arent getting saved in sql.I am trying to update multiple rows in gallery but this code is not working. My gallery items is colAllChannel  even collection is not getting updated
    )
     
     
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
     
    If you are trying to Patching Gallery items then please try below code: 
     
    Submit button - On Select Property code:
    ForAll(
        Gallery.AllItems As r, //Replace - Gallery control name with your gallery name 
        Patch(
            'GPS.fct_tapp_wip_channel',
            LookUp('GPS.fct_tapp_wip_channel', ID = r.ID),
            {
                Tgt_TDP: Value(r.TextInput_TDP.Text), //Replace - TextInput_TDP with your text field name from gallery
                Tgt_HEL:Value(r.TextInput_HEL.Text)  //Replace  - TextInput_HEL with your text field name from gallery 
             
            }
        )
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
     
     
  • HK-21101814-0 Profile Picture
    19 on at
    Hi @Kalathiya  
     
    The code which you provided to patch( update gallery) works fine records getting saved in SQL but it is taking too long to save. My gallery just has 60 records I am using pagination but its taking too long to save to SQL. Could you please help this out?
    ForAll(
        ch_gallery.AllItems As r, //Replace - Gallery control name with your gallery name
        Patch(
            'GPS.fct_tapp_wip_channel',
            LookUp('GPS.fct_tapp_wip_channel', ID = r.ID),
            {   GCC_CHANNEL_L1_NAME:r.ch_channel.Selected.Value,
               GCC_CHANNEL_L1_CODE:r.ch_channel_id.Text,
                Tgt_TDP: Value(r.ch_tdp_tgt.Text), //Replace - TextInput_TDP with your text field name from gallery
                Tgt_HEL:Value(r.ch_sos_tgt.Text),
                Tgt_SOS:Value(r.ch_sos_tgt.Text)//Replace  - TextInput_HEL with your text field name from gallery
             
            }
        ))
  • HK-21101814-0 Profile Picture
    19 on at
    Hi @Kalathiya but after sometimes getting this error network error when using patch function: specified record was not found. Its strange 
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @HK-21101814-0

    Thanks for updating me.

    The last error says that the record you are trying to update does not exist in the table. Could you please verify if this record exists in the table?

    Regarding the update taking more time, it is because we are trying to update all the records that are in the gallery. That’s why it is taking some time, it is attempting to update all 60 records.

    In this case, we need to use a collection to store only the data that we want to update. This way, if the gallery shows 60 records but you are updating only 10, it will update only these 10 records.

    On the Change property of all TextInput/dropdown controls (Input Property), write the code accordingly.

    If(IsBlank(LookUp(col_updatedChannel,ID=ThisItem.ID)),
    	Collect(col_updatedChannel, 
    		{
    			GCC_CHANNEL_L1_NAME:r.ch_channel.Selected.Value,
                GCC_CHANNEL_L1_CODE:r.ch_channel_id.Text,
    			Tgt_TDP: Value(r.ch_tdp_tgt.Text), 
    			Tgt_HEL:Value(r.ch_sos_tgt.Text),
    			Tgt_SOS:Value(r.ch_sos_tgt.Text), 
    			ID:ThisItem.ID 
    		}
    	), 
    	Patch(col_updatedChannel, 
    		{ID:ThisItemID}, 
    		{
    			GCC_CHANNEL_L1_NAME:r.ch_channel.Selected.Value,
                GCC_CHANNEL_L1_CODE:r.ch_channel_id.Text, 
    			Tgt_TDP: Value(r.ch_tdp_tgt.Text), 
    			Tgt_HEL:Value(r.ch_sos_tgt.Text),
    			Tgt_SOS:Value(r.ch_sos_tgt.Text)
    		}
    	)
    );
     
    Submit button - On Select Property code:
    ForAll(
        col_updatedChannel As r, 
        Patch(
            'GPS.fct_tapp_wip_channel',
    			LookUp('GPS.fct_tapp_wip_channel', ID = r.ID),
    			{   
    				GCC_CHANNEL_L1_NAME:r.GCC_CHANNEL_L1_NAME,
    				GCC_CHANNEL_L1_CODE:r.GCC_CHANNEL_L1_CODE,
    				Tgt_TDP: Value(r.Tgt_TDP), 
    				Tgt_HEL:Value(r.Tgt_HEL),
    				Tgt_SOS:Value(r.Tgt_SOS)
            }
        )
    ); 
    Clear(col_updatedChannel); 
    After this, make sure you reset your colAllChannel and refill it to show the updated data in the gallery, if needed. 
     
    On Screen Visible Property: 
    Clear(col_updatedChannel);
    ---------------------------------------------------------------------------------------------------------------------------------------
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard