✅ Getting a single value in sql db
I am currently making a information system for our project in school and I am stuck at the login part wherein I need to get the role value of the username and password so they'll go to their respective panel once they've clicked logged in. I've been searching online and couldn't find an answer.
Currently this is my code for my login button that i've followed in Youtube.
The database currently has ID, Name, Password, and Role. I need to get the Role of the current Name and Password that was used to login so i can put it in the panelMaster() so it'll go to their own panel.
29 Replies
is the role just a string in the user entity or is it a seperate entity
it's a string
thanks 1 sec
and this is for how my db was created and checked if there's a db
something like this I have written it in notepad so could be some syntax errors
im confused why is ur user a list<string> ❓
can you post a screenshot of the full code
ah sorry, it's because of the code of my groupmate made, since he was testing things out without using any database
that's the login code
ow
you still using any
i've sent all the codes that was used for the login
it was part of the tutorial that i saw
what you are doing is also fine but to get the role you would need to make a second query
i haven't gotten the chance to play around yet since our professor wants it working
like this again?
i was thinking of changing any, but idk what to change it to get the role of the current username and password
this is what's inside the db
but if you do this you call the db twice
so I reccomend this
var user = Context.Users.FirstOrDefault(u => u.Name == Username && u.Password == Password);
so you can check if the user exists and then get the role
Ok, I'll test it out
the second one I hope 😄
Why does it makes two calls? Asking bc it seems that it does one
Is it because you chain two operations?
the code also doesn't work made a mistake but I meant that he first checks if the user exists and then with a separate call gets the role
which I recommend doing in one call
I see, for some reason I thought EF optimized that
Thank you so much! it works
nice!
I mean you can chain commands I meant
var userExist = context.any
var role = context.select
are 2queries
I'll now be able to continue with adding in the db and searching them
thank you so much again!
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Use the /close command to mark a forum thread as answered
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View