Bind query result to datatablde
Sample in C# or VB.NET are welcome.
I want to bind the following query r开发者_Python百科esult to datatable:
Dim query = From c in db.Customers _
Where c.Status = "Active" _
Select c.CId, c.FirstName, c.LastName, c.Email
Thanks.
Try this:
Dim dtCustomer = New DataTable("Customer")
dtCustomer.Columns.Add("CId", GetType(Integer))
dtCustomer.Columns.Add("FirstName", GetType(String))
dtCustomer.Columns.Add("LastName", GetType(String))
dtCustomer.Columns.Add("Email", GetType(String))
For Each q In query
dtCustomer.Rows.Add(New Object() {q.CId, q.FirstName, q.LastName, q.Email})
Next
Check out DataTable class on MSDN
精彩评论