How do I separate the values in my query or .ToList() into variables I can access in Entity?

Below I can show the record in a gridView but how do i parse the record field and move them to variables for manipulation?  When i try to put them in a label i get a string of long string of characters but not the value.

string F = "Female";
string L = "licensed";
var HR = OE.tbl_Dept.Where(d => d.Gender.Equals(F) && d.Licensed.Equals(L) );

DeptGrid.DataSource = HR.ToList();
DeptGrid.DataBind();

Open in new window

bmanmike39Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Where are you trying to access the fields from, DataGrid or the original results from HR. It would also help to see the code you are using.
0
bmanmike39Author Commented:
Preferably from the original HR
0
Fernando SotoRetiredCommented:
Hi bmanmike39;

First I would return a List<tbl_Dept> from the query into HR variable as shown below.

string F = "Female";
string L = "licensed";
var HR = OE.tbl_Dept.Where(d => d.Gender.Equals(F) && d.Licensed.Equals(L) ).ToList();

// Set DataSource as HR seeming it is already in a List object.
DeptGrid.DataSource = HR;
DeptGrid.DataBind();

Open in new window

Now to go through the List<tbl_Dept> and get the values to use in your code you can do the following. Remember that the List<tbl_Dept> is a collection of tbl_Dept objects and so putting the values into a control must be able to display all the values you need to display. For example a Label control can only be assigned on text value so you would need to build a string with new line characters after each entry as shown below.
StringBuilder sb = new StringBuilder();
foreach( tbl_Dept d in HR )
{
    // You access the different fields of d by using the column name used in the database
    // as shown here assuming that the table tbl_Dept has a column called DepartmentName
    sb.Append( d.DepartmentName + "\n" );
}

label1.Text = sb.ToString();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bmanmike39Author Commented:
Thank you!  But I'm still have the problem manipulating each piece of data in the record individually.  the string builder allows me to display it all in a label, but i want to separate it into multiple variables.
0
Fernando SotoRetiredCommented:
In the foreach loop the d is a row from the database table, in this case a row from the tbl_Dept,  with all it columns contain in it. To access any of the properties with in d just enter d.ColumnName and assign it to some variable of the same type as that of the column. For example lets say that the table has a column name DeptNumber and in the database table it is an int then to assign that to a variable in your code called deptNum you would the following.

int deptNum = d.DeptNumber;

If you are still having issues please post the code and any exceptions messages and I will have a look at it.
0
bmanmike39Author Commented:
Excellent!  Thanks,  you have help me with my understanding of how this works greatly!
0
Fernando SotoRetiredCommented:
Not a problem bmanmike39, glad to be of help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.