# SQL Query in ASP .NetCore project Page Events

**URL:** <https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173>\
**Category:** ASPRad Vue\
**Created:** [October 31, 2022, 10:16am UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173 "2022-10-31T10:16:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@Max](https://forum.radsystems.io/u/Max)\
**Post date:** [October 31, 2022, 10:16am UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173/1 "2022-10-31T10:16:10Z")

</div>

Hi All,

and sorry for my English.

Just trying RadSystem from yesterday.

Created a new project .Net Core / Quasar

Before save a record, i would like to find a MAX value in a specific field and increment it of one unit.

I found Page Events section and then reach Pages → → Add → BeforeAdd event.

For sure i know that the SQL query is " SELECT MAX(cod) FROM customer" but how to run the query and obtain the value that i will increment afterward and before save?

I need to work like in Visual Studio or i have direct access to field and to the query with some routines “ready to use”?

I was unable to find information online.

Thanks in advance for your help.

Best regards.

Massimo

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 1, 2022, 12:02am UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173/2 "2022-11-01T00:02:21Z")

</div>

You have access to the variable. There are code snippets on the right side of the **Page Event** panel, double click on them and the code will be added, then you can edit it the way you want to. You can also write your C# code just like you do in visual studio.

---

<div class="post-metadata">

**Author:** ![Max](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@Max](https://forum.radsystems.io/u/Max)\
**Post date:** [November 1, 2022, 6:19am UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173/3 "2022-11-01T06:19:34Z")

</div>

Hi Willvin,

and thanks for your reply.

Can you please help me to find the official documentation where i can find all variable available in every event?

Thanks

Regards.

Massimo

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 1, 2022, 3:01pm UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173/4 "2022-11-01T15:01:18Z")

</div>

[Page Events | Documentation (radsystems.io)](https://docs.radsystems.io/en/pages/page-events)  
The variable is passed to the page event function you see on the editor. And you event code should be written inside the function.

**Example:**

**For [ASP.net](http://ASP.net) (C#)**

```auto
private void beforeAdd(Employees postdata){
    //enter statement here
    postdata.field_name; // Access field
}

```

**For Laravel (PHP)**

```php
private void beforeAdd($modeldata){
    //enter statement here
    $modeldata["field_name"]; // Access field
}

```

**For NodeRad (Node.js)**

```auto
async function beforeAdd(postdata, req){
    //enter statement here
    postdata.field_name; // Access field OR
    postdata["field_name"]; // Access field
}

```

Working on **Page Events** requires you have a basic knowledge on the language used on the project type you are working on.

---

<div class="post-metadata">

**Author:** ![Max](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@Max](https://forum.radsystems.io/u/Max)\
**Post date:** [November 1, 2022, 3:23pm UTC](https://forum.radsystems.io/t/sql-query-in-asp-netcore-project-page-events/1173/5 "2022-11-01T15:23:09Z")

</div>

> [@willvin](#):
>
> **Example:**
> 
> **For [ASP.net](http://ASP.net) (C#)**
> 
> ```auto
> private void beforeAdd(Employees postdata){
> //enter statement here
> postdata.field_name; // Access field
> }
> 
> ```

To run a query to an existing table using the postdata.field\_name as value for where, is there a way to use the existing database connection? As example, a ready to use function or macro? Or i need to access to the db from scratch?

I see this on CodeSnippets to fetch a record but where is explained/detailed this way of access a record?

> [@](#):
>
> var query = (from record in DB.TableModelName select new record{ record.product\_title, record.description, } );
> 
> var records = query.Skip(3).Take(20).ToList();

Thanks.

Regards.

Massimo
