I have created a simple form in Powerapps which has a text input field called name and a data table which shows a list of all customers from a table called customer in a SQL Server database and I have also added a button labelled "Go" on the form.
What I want to do is:
See a blank data table when I first open the form
I would enter a customer name in the name text input field
Click the "Go" button and then the value from the name field will be passed to the SQL Server database in a query which only returns
the records which have the same name
Display the results of the query in the data table.
How can I do this?
Thanks
Assuming you've been able to correctly add your on-premise SQL server as a data source:
You'll want to use a combination of Collect() and Filter()
Assign your user input to a variable using (this isn't strictly necessary)
GetContext({UserVariable: TextInput.Text})
Use a combination of Collect() to store the data you pull from MSSQL, and Filter() to, well, filter the data.
Collect(AppStorageTable1, Filter('[dbo].SqlTable]', ColumnName1 = UserVariable))
If you assign AppStorageTable1 as your data source for your data table, it should now appear. (Note, you'll have to declare/create it before it will appear as an option, but once you've used the name in Collect() it will appear as a data source).
EDIT: The term you likely were looking for is "delegable", a quick search will yield a few articles about it. The "Filter" function will pass the work off to your SQL server, so your app won't be responsible for processing/filtering the data.
Related
I have a query for a report based on an MS Access database (as the program project file). The tables in this database get updated with new fields periodically as new features are added.
We need to be able to support old and new versions of the file for our report, so need to know if there is a way to insert a field into the SQL SELECT query if it does not already exist. (Note: Do not want to create ALTER TABLE type statements, as the field only needs to be added into the result set, not into the table permanently.)
I know you can do something like "" AS [FieldName], but that only applies when you know the field doesn't exist and need to create a blank spot for it (such as when a unioned table does have that field). In this case, the table might have the field so I want to use it if it does, but if it doesn't I want to have it still exist in the query results with a default value.
Any help would be appreciated. (I also know you can force the user to update the file, but that option was stated as "only last resort".)
Thanks,
Chris
I am working with an ODBC connection between Access 2013 front end and a SQL Server 2008R2 back end. I have both “Datasheet” and “Continuous” forms that display multiple records which are sorted on an “order” field (integer).
The record source of these forms is a query (an Access local query right now, but I don’t think that switching it to a SQL Server view will solve my problem). Users use these forms to set/update the order of their records for reporting purposes.
My problem: the forms are updateable, but keep throwing the error
The data has been changed. Re-edit the record.
I know this error can be solved by setting the respective form to re-query after every update, but that is equally frustrating to the user because then their records are constantly re-sorting on them as they are trying to set the order (and the form "blips" after every entry).
(I have the field "Timestamp" in all my tables. I know a similar error is raised if one does not have this field in a SQL BE database linked to an Access FE.)
What is the best way to allow the users to update the order of all their records without the form resorting on them? (I would like to keep the “sort” in the query on the “order” field so when they open the form next time it displays the records in the order they specified.) I’ve read about using unbound forms with a stored procedure to update the SQL data, but this seems to be useful for one record at a time. Could I use a temp local table, and then do a batch update with a stored procedure? If that is the best answer, I also ask for some example code to get me headed in the right direction. :)
A simple answer! Add Me.Refresh to the AfterUpdate event on the form or subform. Then when a user does want to update the form based on their new order, they can click a "refresh" button that is set to Me.Requery or Me.Parent.Requery depending on the form or subform, respectively.
I have a Access DB with SQL Server as Backend DB, all the tables in Access are linked from SQL Server. I want to create a query by form for keyword search. I am planning to have a access form such as:
Step 1: Shows a dropdown that lists all the tables in the DB, once a table is selected
Step 2: another dorpdown shows up that lists all the column names in the selected table, once a column is selected
Step 3: then a text box appears where I enter a keyword that will run a select query on the selected table with the criteria on the selected column that is entered in the text box and gives the result.
Now I have a SQL Server query to list the column names of a given table.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = 'table-name')
ORDER BY ORDINAL_POSITION
I want to use this query for the second step.
I cannot understand how to connect Access QBF to run a query in SQL Server.
Should I make a view or stored procedure in SQL Server?
Can someone please tell me how to get this done.
Thank You.
There is an easy way to do this using MS Access.
If you set the row source of table select combo to:
SELECT [name] FROM msysobjects WHERE type=4;
Then add a little code:
Private Sub cboTable_AfterUpdate()
Me.cboFields.RowSource = Me.cboTable
End Sub
And set the field selection combo Row Source Type to Fields, you should get what you want.
You can link views from SQL Server to MS Access.
I have an Access 2010 utility that is designed to query an Oracle DB via ODBC connection as Linked Tables. I created a simple form with two textbox's and a command button. The command button launches VBA code "DoCmd.OpenReport".
The report query Where clause looks like this:
WHERE (((PRODLAW_ITEMLOC.LOCATION)=[Forms]![frm_Qry_ByItem&Loc]![txtLocation]) AND ((PRODLAW_ITEMMAST.ITEM)=[Forms]![frm_Qry_ByItem&Loc]![txtItem]));
the values of txtItem and txtLocation are the user supplied values from the form.
This returns an empty dataset as it is now. If I query a local table, (using a single ODBC query to extract all possible values into a single local table) this method works without any issue other than the 8-10 minutes it takes to refresh the local table. If I replace the query criteria "[Forms]![frm_Qry_ByItem&Loc]![txtItem]" with a simple direct value like "1234" (assuming 1234 is a valid item number), it works without issue.
I've tried to explicitly convert the value of the textbox like "Cstr([Forms]![frm_Qry_ByItem&Loc]![txtItem])" but it made no difference. As this is a query, I can't simply create a breakpoint and examine the properties of the variables so I'm left scratching my head. I've spent hours searching SO and other sites for clues but found nothing related.
Please advise. Thanks!
mfc
TClientDataset.RefreshRecord no longer generates the table join part of SQL when trying to refresh a record on a ClientDataset connected to a dataset with a joined table in the SQL statement.
As a result, calling this method results in SQL error "invalid column names" for each field not in the main table.
This was not a problem in Delphi 2010 and earlier.
The error occurs with both DBX4 or BDE components connected to the TClientDataset and thus it is highly likely the issue is a problem with changes to TClientDataset code.
To replicate this problem:
Create a new app in Delphi XE with only a single form and drop the required database components on it (TSQLMonitor, TSQLConnection, TSQLQuery, TDatasetProvider, TClientDataset, TDatasource, and TDBGrid) and bind them to each other.
Created a simple SQL statement with a table join and placed this in the TSQLDataset.SQL property.
The SQL statement included just two fields - the key field of the main table, and a field from a joined table - for example in pseudocode:
Select
MainTable.IntegerKeyField
, JoinedTable.JoinField
FROM MainTable
LEFT OUTER JOIN JoinedTable ON MainTable.LookupFieldID = JoinedTable.JoinKeyField
Add both of these fields as persistent fields in both TSQLQuery and TClientDataset with Provider Flag for the key field including pfInKey (RefreshRecord will not work if it does not know which field is the key hence persistent fields is a must).
Add two buttons on the form - one just opens the Clientdataset and the 2nd button calls clientdataset.refreshrecord;
Run the app, press button to open dataset and data displays in the grid.
Press the Refresh Record button, and you will get SQL error "invalid column name" for the joined field.
Close the app, open the SQLMonitor log and in the refresh record SQL statement that Delphi generated, you will see it has not included the table join statement.
====
I would really appreciate any ideas on how to fix this.
Try using a view on the database to implement the required join. Then the delphi component can just select from view_name rather than have to handle the join itself.