Sneha K

Sneha K

  • 1.2k
  • 527
  • 195.8k

How to retrieve table values from database one by one in mvc

Oct 24 2016 8:15 AM
Hi i want to retrieve particular table values from database and need to assign each values to each variable in mvc5. My question is little tricky and maybe some times it will confuse you dudes. I will explain my issue clearly
 
 
 

This is my employee table and it contain 2 fields called EmployeeID and DisplayName . EmployeeID is primary key. What i need is i want to retrieve these tables values one by one and assign that values (Which i retrieve one by one from table ) to variables.

Eg

 var1 = yasin  var2 = rajan..
 I tried one method . In that method i gave hardcode to find each Id one by one. But hardcode is not correct way for professional developer right.
 
 
 
 I tried one method . In that method i gave hardcode to find each Id one by one. But hardcode is not correct way for professional developer right.
 
Eg:
 
 var yasinempid = (from emp in db.Employees where emp.DisplayName == "Yasin" select emp.EmployeeID).FirstOrDefault();

Now i want to find the ID of yasin employee.so i gave yasin value directly in the query. But this is not correct way because i have limited no of employees so i can able to find employee ID easily . But i have lot of employees means this hardcode value is not correct way and also it wont give correct solution right . So that i need alternate solution for this problem.

I tried my level best to explain this issue. Any one understand my issue and help me to resolve this problem.

Advance thanks.

 
 

Answers (4)