Link to home
Start Free TrialLog in
Avatar of GeneBe
GeneBeFlag for United States of America

asked on

Convert DataTable to List

I have a working code but I would like to convert a block of code into a class a just call the classs. See code below.
DataTable results = dataAccess.Billing.GetDataTable(selectQuery);

                // Convert Table to List
                List<Service> serviceLines = new List<Service>();
                serviceLines = (from DataRow dr in results.Rows
                                select new Service()
                                {
                                    MemberNbr = dr["MEMBER_NBR"].ToString(),
                                    AffNbr = dr["AFF_NBR"].ToString(),
                                    AmtAllowP = Convert.ToDecimal(dr["AMTALLOW_P"]),
                                    AmtCharge = Convert.ToDecimal(dr["AMTCHARGE"])
                                }).ToList();

Can I remove this block of code and make a class or constant in another file so it is easy to maintain and just call it?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

of course you can move the code around. Not sure to fully get your question!
Avatar of GeneBe

ASKER

I want to move this block of code somewhere else for easy maintenance and call it.
                                    MemberNbr = dr["MEMBER_NBR"].ToString(),
                                    AffNbr = dr["AFF_NBR"].ToString(),
                                    AmtAllowP = Convert.ToDecimal(dr["AMTALLOW_P"]),
                                    AmtCharge = Convert.ToDecimal(dr["AMTCHARGE"])
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GeneBe

ASKER

That's what I thought but wasn't sure. I needed this advice.
Avatar of GeneBe

ASKER

That's what I thought but wasn't sure. I needed this advice.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GeneBe

ASKER

I will try. thank you!