cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DucMac
Level: Powered On

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
Meneghino
Level 10

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

Hi @DucMac

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
Meneghino
Level 10

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

Hi @DucMac

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

DucMac
Level: Powered On

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
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,989)