-1

How to retrieve data from Database by ( List<> ) instead of data table?

How can I do this?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Green
  • 1
  • 3

1 Answers1

0

Follow these steps

  1. create a class emulating your table
  2. declare the list
  3. retrieve data and bind it to the list
  4. display your data

    public class myListClass { public string myListClassItem1{ set; get; } public string myListClassItem2{ set; get; } public string myListClassItem3{ set; get; } }

    List items = new List();

    while (reader.Read()) { items.Add(new myListClass(reader["Item1"].ToString(), reader["Item2"].ToString(), reader["Item3"].ToString())); }

    myDataGrid.DataSource = items;

    myDataGrid.DataBind();

Prosper
  • 98
  • 1
  • 13