cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Collect/Patch functions do not allow me to use my SQL table as "DataSource"

I am trying to make changes to an sql table using either powerapp functions Collect or Patch but I keep getting an error saying "The first argument of 'Patch/Collect' should be a collection". 

 

The code i used for my button is:
Collect('[dbo].[People]', {FIRSTNAME: TextInput1.Text, ANIMAL: TextInput2.Text, AGE: TextInput3.Text})

 

Some things to note:

- I have connected to the database and am displaying the table already on a gallery in the same page

- I have tested this function with a sharepoint list instead and it successfully creates a new list item

 

I have spent many hours trying to find a solution, any advice would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Collect/Patch functions do not allow me to use my SQL table as "DataSource"

Hi @Anonymous

In order to be able to create new records in a table, the table needs to have a primary key defined in SQL.

In SharePoint every table has a default and immutable primary key, the ID column, so that is why there is never a problem there.

Hope this helps.

View solution in original post

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: Collect/Patch functions do not allow me to use my SQL table as "DataSource"

Hi @Anonymous

In order to be able to create new records in a table, the table needs to have a primary key defined in SQL.

In SharePoint every table has a default and immutable primary key, the ID column, so that is why there is never a problem there.

Hope this helps.

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Collect/Patch functions do not allow me to use my SQL table as "DataSource"

Thank you so much! That was it.

 

(For those looking for a solution, I ran the following code to add a primary key column to my table)
ALTER TABLE People
ADD ID INT IDENTITY
CONSTRAINT PK_People PRIMARY KEY CLUSTERED

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,015)