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.

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.

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
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 352 members 4,184 guests
Please welcome our newest community members: