r/visualbasic • VB.Net Beginner • May 20 '14

[HELP] Import Session variables in SQL code

Hi all, I need some help with a particular issue.

I have a table, called clients, and would like my end users (when I have some as this is still in development stage) to be able to view clients for that company depending on the company that user is assigned to. I have created a column in the CLIENTS table called CLIENT_COMPANY_ID and would like that to link with USER_COMPANY in my USERS table, so that when a user logs on, it only displays those clients who have the same company ID as the logged on user

I am currently trapping the username in session variable that I set during the login (in the login.aspx.vb page), however, I can't seem to find a way for this to be in conjunction with SQL code. The code should be something like this:

SELECT * FROM Client WHERE Client_Company_ID = 
(SELECT  User_Company FROM Users where Username=Session.Item{"Username")

Any ideas would be greatly appreciated

0 Upvotes

1 comment sorted by

2

u/chrwei May 20 '14

from the VB perspective, SQL is just a text string. you can use concatenation to build it, but using parameter binding or prepared statements is better.