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 / Connect a sql database...
Power Apps
Answered

Connect a sql database with a bit field to a toggle switch in a gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi, 

I have a problem regarding the connection between a toggle-switch in a gallery and an sql database, which is managed with Microsoft SQL Server Management. I want to include an toggle in my gallery and switch the bit field with that toggle. Therefore I wrote an OnCheck: 

Patch(table5;First(Filter(table5;'Person ID'=ThisItem.'Person ID')); {'To discuss':true})

and an UnCheck- function: 
Patch(table5;First(Filter(table5;'Person ID'=ThisItem.'Person ID')); {'To discuss':false})

The field changes and I can see the powerapp working with the little dots at the top, but after a few seconds the toggle jumps back to its old position, any reason for that?

Thanks for your help!

 

Categories:
  • WiZey Profile Picture
    3,023 Moderator on at

    Hello @Anonymous ,

     

    Could you check the "Default" property of your toggle and see if it's linked one way or another to your record in your table?

     

    My guess is "Default" is set to true, thus resetting itself back whenever you update the datasource with "Patch()".

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Now all Toggle Buttons are on false. Now I can see the fields changed in the database! So it only needs to now show the right state with the toggle, do you know how I get there?

    thank you for the fast reply, amazing!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I checked the problem in more detail: 
    Now when I start the app all buttons are on false, even if in the database the value is 1=true. 
    1) When now the value in the database is 1 and I set the toggle to 1 in the database, it stays on true, when I set it back to false it overrides the database with a 0. 
    2) When the database value is 0 and I put the toggle in the true state,  it overrides the database, but switches back the toggle on false, the database stays on 1. 
    I hope you can understand what I mean. Thank you for the help!

  • WiZey Profile Picture
    3,023 Moderator on at

    I understand the situation, but I need to know more about the formula you used so I can be sure.

     

    Could you show us how you populated your toggles' "Default" property, their "OnChange" property and the "Items" property of your gallery please?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Yes, of course:

     

    Settings of my toggle: 

    Default: -

    OnChange: -

     

    Setting of my gallery

    Items: table5


     

     

  • WiZey Profile Picture
    3,023 Moderator on at

    Can you try adding this formula in the "Default" property of your toggle?

     

    ThisItem.'To discuss'

     

    This should set the toggle to either true of false based on the value of your column "To discuss" of the record.

     

    With this, when you change the value of the column, the toggle should follow.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi, I tried it, but I won't work properly, now the problem is the following:
    After I added the formula the app looked good, but not long. 

    As I tried to set 1 toggle on true, all toggle were set on true, also in the database. 
    When I try to set it back on false, it loads a few seconds (I can see that it also writes the false value in the database), but jumps back to the true value after the loading process is finished, in the app and the database. In result, I can't flip any toggles on false, when I try it, it only works for a few seconds. 

     

  • Verified answer
    WiZey Profile Picture
    3,023 Moderator on at

    Maybe the "Patch()" is wrong. Can you try with this one?

     

    OnCheck:Patch(table5; ThisItem; {'To discuss':true})
    OnUncheck:Patch(table5; ThisItem; {'To discuss':false})

     

    If it's still not behaving correctly, try using "OnChange" instead:

     

    OnCheck: - 
    OnUncheck: - 
    OnChange: Patch(table5; ThisItem; {'To discuss':Self.Value})
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    The second solution works, thank you! 

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 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 258

#3
Mohsin Ali Profile Picture

Mohsin Ali 231

Last 30 days Overall leaderboard