Nerdynosaur
Nerdynosaur

Reputation: 1888

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];
}

Upvotes: 0

Views: 2254

Answers (1)

tukaef
tukaef

Reputation: 9214

Just call an extension method ToArray():

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

Upvotes: 4

Related Questions