Click here to Skip to main content
15,878,959 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
C#
DataTable dt = new DataTable()
from the data base using dataBaseEntities?
here is my query:
SQL
from data in db.Sources
where data.IdTheme==idtheme
select data.Url;
Posted
Updated 19-May-13 20:33pm
v9

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):

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


var dt = new DataTable();
dt.Columns.Add("Url");
foreach (var url in queryResult)
{
    var newRow = dt.NewRow();
    newRow["Url"] = url;
    dt.Rows.Add(newRow);
}
 
Share this answer
 
Comments
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