cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dhofknecht
Frequent Visitor

Entering Multiple Listbox Values w/ Text Box Value One At A Time to SQL

Hi All,

 

  So the gist of what I am trying to do here is get multiple values to be recorded in SQL as individual records.  I am working with a table called dbo.personfood which is linked to the dbo.person table by the personid.  What I am trying to do is enter the personid into a textbox and then select the different food items from a listbox but have them enter as individual records.  This post got me going in the right direction, https://powerusers.microsoft.com/t5/PowerApps-Forum/Passing-Multiple-Values-from-Listbox-one-at-a-ti..., but didn't completely solve my problem.

 

  An example of what I am trying to do is if the user enters 11 for the personid in the textbox and then select chocolate, bread, and milk from the listbox the data will enter into the personfood table as:

personid     fooditem

11                chocolate

11                bread

11                milk

 

  Is there any way to do this?  I know the forall statement can be used with listboxes to have each value get its own row in a SQL table but can this be used in combination with a textbox?

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-micsh-msft
Community Support
Community Support

Hi @dhofknecht,

 

Yes, that could be done with the formula I shared in the previous thread, assuming you have the personId field defined in your SQL table.

Then the formula would be changed as below:

ForAll(ListBox1.SelectedItems.Value,
Patch('[dbo].[Foods]',
Defaults('[dbo].[Foods]'),
{foodName:Value,
personid:value(TextInput1.text)}
)
)

Take a try with the formula above.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-micsh-msft
Community Support
Community Support

Hi @dhofknecht,

 

Yes, that could be done with the formula I shared in the previous thread, assuming you have the personId field defined in your SQL table.

Then the formula would be changed as below:

ForAll(ListBox1.SelectedItems.Value,
Patch('[dbo].[Foods]',
Defaults('[dbo].[Foods]'),
{foodName:Value,
personid:value(TextInput1.text)}
)
)

Take a try with the formula above.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This worked perfectly for what I was trying to do!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

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