Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,

I have a datatable and want to return this type -
C#
object[] vals = {
                           new{ id=1, name="Java"},
                           new{ id=2, name="Javascript"},
                           new{ id=3, name="AJAX"},
                           new{ id=4, name="ASP.NET"},
                           new{ id=5, name="PHP"},
                           new{ id=6, name="CPP"},
                           new{ id=7, name="C"},
                           new{ id=8, name="C#"},
                           new{ id=9, name="CSS"},
                           new{ id=10, name="HTML" }
                       };
       return vals;






how we do datatable to array?
Posted
Comments
[no name] 13-Jun-14 7:15am    
And the problem is? What have you tried?

1 solution

You can try this :


DataTable
C#
DataTable dtTechnology = new DataTable();


Class for Object
C#
public class TechnologyData
    {
        public int Tech_id { get; set; }
        public string Tech_name { get; set; }
    }


Code to Insert into Array
C#
public static TechnologyData[] GetTechnologyData()
    {
        List<technologydata> Details = new List<technologydata>();

        DataTable dtTechnology = new DataTable();

        foreach (DataRow dr in dtTechnology.Rows)
        {
            UserData SetData = new UserData();
         
            SetData.Tech_id=Convert.ToInt32(dr["ColumnName"])
            SetData.Tech_name=Convert.ToString(dr["ColumnName"])

            Details.Add(SetData);
        }

        return Details.ToArray();
    }
</technologydata></technologydata>


Best of luck buddy...... :)
 
Share this answer
 
v2

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