简体   繁体   中英

How to read data from database and store it in array using linq to sql?

I create a database with the data(id) 8,5,1,9,2,3,4,5. Then i want to retrieve the data and store it in an array. Does anyone can help me? I am using C# and linq to SQL.

My code:

using(DatabaseDataContext db = new DatabaseDataContext())
{
   var query = from p in db.table1
               select p.id;


   int[] myArray = new int[query];
}

Just call an extension method ToArray() :

var array = (from p in db.table1
             select p.id).ToArray();

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