This topic is locked

SQL select based on what user is using the system...

3/18/2022 8:15:42 AM
ASPRunner.NET General questions
H
houseofit author

Hi all

Hope you can help me...

How do I make a SQL select based on what user logs in - Want to only shows users records in all views.

I thought I saw a video about this once but can't find it..

Regards Thomas

H
houseofit author 3/18/2022

I tried a simple example from the manual and placed in "List Page : Before SQL" but it won't compile

if (Security.getUserName() != "admin")
{
query.addWhere("DATEDIFF(day,DateColumn, GETDATE()) <= 7");
}

If I even can't get the syntax right I have a problem :-)

Hope you can help...

Ps. Aren't there an event where I can add this query before everything so everything based on this table will be filtered...

F
Frank R 3/18/2022

Please explain what you need to do more.

Also, before you go down a road, read the whole Security chapter. It's highly likely you can achieve what you need with built-in security, with no code.

Sergey Kornilov admin 3/18/2022

You may want to check Avanced Security option "Users can see and edit their own data only". No coding is required.

H
houseofit author 3/21/2022

Hi again

The DB is not created/maintained by ASP runner so I can't quite change it.

Records are created for some statistic use, and the user displays them in list and reports are created in ASP runnner.

I have a source fields in the DB that tells where the data is from so what i want is that :

User 1 : can see legeparken1 and legeparken 2
User 2 : can see legeparken3 and legeparken 4

That selection should be made on views and reports based on what user it logged in.

View from table is attached.

img alt

REgards Thomas T

Sergey Kornilov admin 3/21/2022

Use the technique specified in this article:
Dynamic SQL Query

T
Tuong Do 4/12/2022

Hi houseofit,

query.addWhere need to be in After table initialized event

You can not do it in Before SQL event