简体   繁体   中英

How can I convert each record from query result to arraylist c#

Sorry as I am new to C# I want to convert each record retrieved from the DATABASE to arraylist my code is as follow:

var reservation = from x in db.resrvation \
                  where x.date=Calendar1.SelectedDate 
                  select x;

Here I want to get each record in reservation and convert it to array so i can gets specific data eg client name

The collection retrieved by reservation include no. of records each of them have properties such as clintName, Phone, ReservationDate,..etc I want to make an arraylist for each record .

Actually I am trying to use this arraylist to fill datatable raw.

Just convert to List and you are done.

var reservations = (from x in db.resrvation 
                   where x.date=Calendar1.SelectedDate 
                   select x).ToList();

Well, to convert it to an Arraylist you can do this:

(from x in db.resrvation where x.date=Calendar1.SelectedDate select x).ToArrayList();

Assuming you have this extension method:

public static ToArrayList(this IEnumerable source)
{
    var a = new ArrayList();
    foreach (object item in source) a.Add(item);
    return a;
}

However, I'd use a generically-typed List<T> instead, like this:

(from x in db.resrvation where x.date=Calendar1.SelectedDate select x).ToList();

It sounds like you want to select an ArrayList for each row. Try this:

var reservation = from r in db.reservation
    where r.date == Calendar1.SelectedDate
    select new ArrayList(new object[] { r.name, r.whatever });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM