GeneBe
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.GetData Table(sele ctQuery);
// 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["AMTA LLOW_P"]),
AmtCharge = Convert.ToDecimal(dr["AMTC HARGE"])
}).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?
DataTable results = dataAccess.Billing.GetData
// 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["AMTA
AmtCharge = Convert.ToDecimal(dr["AMTC
}).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?
of course you can move the code around. Not sure to fully get your question!
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["AMTA LLOW_P"]),
AmtCharge = Convert.ToDecimal(dr["AMTC HARGE"])
MemberNbr = dr["MEMBER_NBR"].ToString(
AffNbr = dr["AFF_NBR"].ToString(),
AmtAllowP = Convert.ToDecimal(dr["AMTA
AmtCharge = Convert.ToDecimal(dr["AMTC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's what I thought but wasn't sure. I needed this advice.
ASKER
That's what I thought but wasn't sure. I needed this advice.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try. thank you!