troubleshooting Question

Convert DataTable to List

Avatar of GeneBe
GeneBeFlag for United States of America asked on
DatabasesC#
7 Comments2 Solutions73 ViewsLast Modified:
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?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros