简体   繁体   English

如何将每个记录从查询结果转换为arraylist C#

[英]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: 抱歉,由于我是C#的新手,我想将从DATABASE检索到的每个记录转换为arraylist,我的代码如下:

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 . 的每个记录都具有诸如clintName,Phone,ReservationDate等属性。我想为每个记录创建一个数组列表。

Actually I am trying to use this arraylist to fill datatable raw. 实际上,我正在尝试使用此arraylist填充数据表原始数据。

Just convert to List and you are done. 只要转换为List ,就可以完成。

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: 好吧,要将其转换为Arraylist您可以执行以下操作:

(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: 但是,我将改用通用类型的List<T> ,如下所示:

(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. 听起来您想为每行选择一个ArrayList。 Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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