Click here to Skip to main content
15,917,617 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have makea query on table and get the ID of that table.Now i want to get all names using that and want to save in an array i have tried some tell me it is right or not.

XML
Department_PR_LKS objDept = SystemSetupsController.GetDepartmentByDepartmentId(CompanyId);

                    List<Employee_AttandanceLogs_PR_View> objActiveDept = SystemSetupsController.GetAllActiveDepartmentsByID(objDept.DepartmentId);




foreach (var item in objActiveDept)
{
Array name= item.DepartmentName.ToArray();

}
Posted
Updated 5-Feb-14 20:15pm
v2
Comments
Karthik_Mahalingam 6-Feb-14 1:50am    
not clear, provide more info and code..
Sergey Alexandrovich Kryukov 6-Feb-14 1:55am    
More code? Aren't you joking? Even this code is way too much. Rather, OP needs to explain what is he trying to achieve.
I answered based on this code, please see...
—SA
Karthik_Mahalingam 6-Feb-14 2:04am    
SAmight be he is new to this field and struggling a bit i guess.
fak_farrukh 6-Feb-14 2:11am    
look on objActiveDept i have all ids department which i have get from query. Now i want to det deparments name using foreach loop and save into an array. hope you understand now
fak_farrukh 6-Feb-14 2:16am    
Now i have updated more code

Try this..


C#
string[] departmetnNames;
       List<string> lstTemp = new List<string>();
       foreach (var item in objActiveDept)
       {
           lstTemp.Add(item.DepartmentName);
       }
       departmetnNames = lstTemp.ToArray();
 
Share this answer
 
It is quite unclear what do you want to achieve, so I cannot answer this question because this is not a valid question.

All I can advise is: look at your code: it makes no sense at all. You create some array object inside loop, assign its reference to some local variable and immediately loose this object when you go to next iteration. Please don't ask me "what to do instead", because I have no idea what you want to achieve; just don't do what makes no sense for any purpose.

—SA
 
Share this answer
 
Comments
fak_farrukh 6-Feb-14 2:03am    
look on objActiveDept i have all ids department which i have get from query.
Now i want to det deparments name using foreach loop and save into an array.
hope you understand now
Sergey Alexandrovich Kryukov 6-Feb-14 2:16am    
I already took a look at it. Now it's your turn to look. You are looking but not seeing.
This is you who don't understand.
Do you need array, or array of arrays (to hold all the items)?
—SA
Sergey Alexandrovich Kryukov 6-Feb-14 2:20am    
You did not show declaration of the Employee_AttandanceLogs_PR_View. It should have DepartmentName. But is DepartmentName an array, too? Why?!
Maybe all you need is to call
objActiveDept.ToArray().

—SA
CPallini 6-Feb-14 3:35am    
My 5 to counter the silly downvote.
Please, be patient :-)
Sergey Alexandrovich Kryukov 6-Feb-14 8:20am    
Thank you, Carlo.
Not a big deal; for the ignorant, it's usual to blame others... :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900