How can i get Id item number in entity data model

Multi tool use
Multi tool use


How can i get Id item number in entity data model



i'm trying to check the login information ,,, and get the item Id if they are correct ,,, Otherwise show error entry message
my code is:


var getid = from user in db.tables
where user.name == tbusername.Text && user.password == tbpassword.Text
select user.Id;

c = Int32.Parse(getid);



but the vs say there's an error at c = Int32.Parse(getid); What's wrong?


c = Int32.Parse(getid);





don't mind ,,, like "username or password is incorrect"
– Muhammad Aaref Al-Shami
Jun 30 at 8:54





"username or password is incorrect" is not your only troubles
– TheGeneral
Jun 30 at 8:58


"username or password is incorrect"





nope ,,, i can't check whether the username and password are correct or no and get id if they are right
– Muhammad Aaref Al-Shami
Jun 30 at 9:06





1 Answer
1



You cant convert a list to an integer. Where returns a collection, (or said better an IEnumerable). You are pushing a list of something into a space (Int32.Parse) that only wants a 1 of something.


Where


IEnumerable



Also if your Id is an int, you shouldn't have to parse it



Example


var getid = (from user in db.tables
where user.name == tbusername.Text && user.password == tbpassword.Text
select user.Id).FirstOrDefault();

// or
var getid = db.tables.Where(user => user.name == tbusername.Text && user.password == tbpassword.Text)
.Select(user => user.Id)
.FirstOrDefault();

if(getid == null)
{
MessageBox.Show("Oh nooez!!!");
return;
}

MessageBox.Show("You is id : " + getid );



Enumerable.FirstOrDefault Method (IEnumerable)



Returns the first element of a sequence, or a default value if the
sequence contains no elements.



Enumerable.Where Method (IEnumerable, Func)



Filters a sequence of values based on a predicate.



Return Value



Type: System.Collections.Generic.IEnumerable An
IEnumerable that contains elements from the input sequence that
satisfy the condition.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ao 8qluOPey9960SoK,i3YJB o03yfrTgFked orpXYy
vZGVdiL,02L

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya