I am using this to select record
public IEnumerable<Employee> SelectEmployeeById(int id)
{
DataClassesHrPortalDataContext dc1 = new DataClassesHrPortalDataContext(dbConnStr);
System.Data.Linq.Table<Employee> location = dc1.GetTable<Employee>();
return dc1.Employees.Where(a => a.emp_id == id);
}
but how i can retrieve the record in
But how i can fill the record in textbox
private void fillsalarydetail()
{
PioneerDataAccess.EmployeeClass empcls = new PioneerDataAccess.EmployeeClass();
var obj = empcls.SelectEmployeeById(3);
//I am not able to do this
txtSalEmpName.Text=obj.
txtsalempcode.Text=
}
Because of linq differed execution make use of tolist method and than get read data will do you task
var obj = empcls.SelectEmployeeById(3).ToList();
textvox.Text= obj[0].Nameofproperty;
.Where extension Method return IEnumerable List. so get The Top element or get Single Element from list.
EmployeeClass Emp = empcls.SelectEmployeeById(3).ToList();
if(listofEmp.Count() > 0)
{
EmployeeClass obj = listofEmp[0];
or
EmployeeClass obj = listofEmp.Top(1);
or
EmployeeClass obj = listofEmp.Single();
//then assign your values to testbox use class properties as:
txtSalEmpName.Text=obj.Name;
txtsalempcode.Text= obj.code;
}
You can do this as:
EmployeeClass Emp = empcls.SelectEmployeeById(3).SingleOrDefault();
if(Emp != null)
{
txtSalEmpName.Text=obj.Name;
txtsalempcode.Text= obj.code;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.