I am trying to make an app that shows a users past expenses with C# querying a SQL Database.
I have a program that shows the user their current expenses.
They have to login using a unique username and password. When logged in, they should see only their expenses from the expenses table.
I am currently using:
Select * from ExpensesTbl
Which shows everything, including other users information. I believe I need to use a WHERE clause, but I am unsure what it would look like as Im not sure what user is logged in.
In example, table Expenses currently has two users (A and B).
Can someone point me to how I can get just the information that pertains to only the logged user, instead of the information of all users?
CodePudding user response:
The solution for this is using IDs on each user, on ExpensesTbl create a Foreign Key that binds the ID with the information of this user on ExpensesTbl, then just do a
SELECT * FROM WHERE ExpensesTbl.user_id = LoggedUser.id
Please, take a read at those documents:
https://www.w3schools.com/sql/sql_foreignkey.asp
https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html