This topic is locked
[SOLVED]

 How do I use a user's login value in a query

10/7/2019 16:42:15
ASPRunner.NET General questions
A
alevin16 author

We have, what I believe, is a simple setup. On Microsoft Azure we have 2 tables. One is a list of Customer info and the other is what they bought (so a one to many relationship). I can connect to it from the ASPRunner.net project window so that is good. What I need to know how to do is to connect the user login value to the tables.
We have about 6 locations. When a Manager from Alpha location logs in using the login "Alpha", I want the word "Alpha" to be used as a filter on the Customer table always (any other filters would be added to this, the filter by location HAS TO stay on, we do not want managers seeing customers from other locations). This way people from the Alpha office can ONLY see customers from the Alpha office. Same if a person from Beta location logs in, the program takes the word "Beta" and uses it as a filtering parameter. The goal is to have all our customers in one table with a field called "Sales Location" (which would have the word Alpha, Beta, Gamma, Delta, Epsilon, Zeta).
Otherwise I guess I would have to have 6 customer tables and 6 connected purchased tables which I really do not want to do because expansion would be tough.
Does anyone know how I pass the userid variable?
Thanks!

N
Nir Frumer 10/7/2019
A
alevin16 author 10/8/2019

That was very helpful. The only issue I have now is that my field name has a space in it. I have tried many different things but since I am not familiar with C# I am poking in the dark. Here is what I have
dynamic userData = Security.getUserName();

query.addWhere("'Test Name'" + "=" + "'" + userData.ToString() + "'");
It compiles but returns no records (I am using an old table that has fake data in it dealing with hormones)
In SQL I would use [Test Name] but the system does not like []'s
When I did an echo I saw 'Test Name' = 'Cortisol' This should have filtered the table down to about 40 records but I get no data.
Any ideas?

Sergey Kornilov admin 10/8/2019

This is SQL and you need to use [] as field name wrappers.

query.addWhere("[Test Name]='" + userData.ToString() + "'");
A
alevin16 author 10/8/2019

Thank you thank you!!!
I swore I tried that but I must have missed something (I was trying all sorts of combos).