Overview
Wayfast Datasets allow us to connect a page with a data source like a database or an API. Databases are one of the Wayfast Pillars. Wayfast Application Project’s are mostly used to interact with databases data sources and Datasets are the mean to achieve that goal. As a general rule we suggest using Stored Procedures to interact with databases bug but Datasets can run ad-hoc queries too.
...
Today we are going to review how to execute a store procedure for reading data and displaying it in a Grid.
Preconditions
Before we start, this lesson assumes the following preconditions:
We already have a project connected with a database. You can find more details here: Attach or create databases. Let’s reuse our Hello World Project.
We need an active requirement so we can create objects in our database.
This lesson assumes you already know what a stored procedure is. If you don’t you can read about them here.
Step 1: Create database object and update Wayfast DB Model
First let’s connect to the project’s database using SQL Server Management Studio.
Click new query and paste the following script to create a table and a stored procedure:
Code Block | ||
---|---|---|
| ||
CREATE TABLEPROCEDURE HWD_Roles ( Name nvarchar(50), Role nvarchar(50), Email nvarchar(50), ) GO CREATE PROCEDURE spHWD_Roles_Get AS BEGIN SELECT * FROM HWD_Roles with(nolock) END GOspHelloWorld_GetRoles AS DECLARE @Result TABLE(Id INT, RoleName NVARCHAR(128), RoleDescription NVARCHAR(256)); INSERT INTO @Result VALUES (1, 'Admin', 'Can do everything') INSERT INTO @Result VALUES (2, 'HR Manager', 'Can create position and approve hiring processes.') INSERT INTO @Result VALUES (3, 'HR Lead', 'Can edit positions and start hiring process.') INSERT INTO @Result VALUES (4, 'HR Analyst', 'Can read positions and and add candidates.') SELECT Id, RoleName, RoleDescription FROM @Result |
Every time we edit our database we need to synchronize Wayfast DB Model so Wayfast is aware of all the changes we just did.
To do that let’s go back to Wayfast, navigate to “Databases” and click on the “Synchronize DB” button on menu.
...
A popup is will be displayed, just click on the “Synchronize” button.
...
Once the popup closes all new database objects are available in wayfast.
How to create a new Dataset? (IN REVIEW)
Go to “Project Pages” at the top menu. Select any of the pages available in the project. Then click on “New Dataset” button
...
Now that we have can retrieve data from our DB we need to show it in the Application’s UI.
How to connect a Dataset with a Grid?
Let’s create an example using grid columns linked to the new dataset.
...
All the information in the table is now available in the page. In the following lesson, we are going to analyze how we can insert values on the table using “Actions” feature.
Recap
In the first part, we learnt how Pages interact with database by creating Datasets. Then we made a first approach using SQL to create a simple Stored Procedure that was linked to Dataset. In the second part, we explained how the Controls under pages can display in different ways the information available on database, assigning the place and source. In the next lessons, we will learn how to connect the Controls with Actions that user will have in pages to make the application more dynamic.