Click here to Skip to main content
15,798,592 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm developping a windows form application with ADO .Net entity data model , how can i fill a DataTable
DataTable dt = new DataTable()
from the data base using dataBaseEntities?
here is my query:
from data in db.Sources
where data.IdTheme==idtheme
select data.Url;
Updated 19-May-13 21:33pm

1 solution

Is there any specific reason why you would want to transform your IEnumerable<string> into a DataTable?

Anyway you can probably do something like this (untested):

var queryResult = from data in db.Sources
where data.IdTheme==idtheme
select data.Url;

var dt = new DataTable();
foreach (var url in queryResult)
    var newRow = dt.NewRow();
    newRow["Url"] = url;
Share this answer
Nnorss 20-May-13 3:13am    
Thank you Guirec! I want to put the results into a listBox thats why i used a dataTable.
Guirec 20-May-13 3:15am    
then you don't need to transform into a datatable...
you just have to bind your result to the listBox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900