web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Inserting a record in ...
Power Apps
Unanswered

Inserting a record in SQL table from PowerApp

(1) ShareShare
ReportReport
Posted on by 23

I'm creating an App and I want a record to be inserted into SQL table once I click Submit.

So, in the submit button, Onselect I wrote a patch as below,

Patch(
    UserChangeLog;
    Defaults(UserChangeLog),
    {
        M3_User: UserID.Text,
        M3_ChangeDate: DatePickerFrom.SelectedDate,
        M3_MasterFacility:FacilityLabel.Text,
        ActualRevertTime:DatePickerFrom.SelectedDate,
        M3_ChangeFacility:FacilityDropdown.Selected.CFFACI,
        Processed:UserID.Text,
        ScheduleRevertTime:DateAdd(DatePickerFrom.SelectedDate,1,TimeUnit.Days) + Time(0,0,0,0)
    }  
)
 
Patch seems to be correct as Power App did not show any error. I revised a few time to get this.
 

Now, my SQL table name is dbo.UserChangeLog.

COLUMN_NAME                  DATA_TYPE
M3_User                              nchar
M3_MasterFacility               nchar
M3_ChangeFacility             nchar
M3_ChangeDate               datetime
Processed                          char
ScheduleRevertTime      datetime
ActualRevertTime          datetime

 

When I run my app in development mode, record is not getting inserted to the table.

I checked the permissions in SQL, I'm the DB owner. Don't know what else should I check. Please guide.

 

Thanks,

Vishwa

 

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @Vishwak 

     

    can you try this approach please:

    Patch(
     UserChangeLog;
     Defaults(UserChangeLog),
     {
     M3_User: UserID.Text,
     M3_ChangeDate: DatePickerFrom.SelectedDate,
     M3_MasterFacility: FacilityLabel.Text,
     ActualRevertTime: DatePickerFrom.SelectedDate,
     M3_ChangeFacility: FacilityDropdown.Selected.CFFACI,
     Processed: UserID.Text,
     ScheduleRevertTime: DateAdd(DatePickerFrom.SelectedDate,1,Days) + Time(0,0,0,0)
     } 
    );
    If(IsEmpty(Errors(UserChangeLog)), Notify("Record added successfully", NotificationType.Success), Notify("Failed to add record: " & Errors(UserChangeLog).Message, NotificationType.Error));
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • VK-23090237-1 Profile Picture
    23 on at

    Thank you. No, still the SQL table is not getting updated.  I tried with your patch and it gave me a success message that record got inserted successfully but when I checked in the SQL table, data is not updated. What could be the reason, any idea?

     

    Thanks,

    Vishwa

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard