views:

15

answers:

1

Sample in C# or VB.NET are welcome.

I want to bind the following query result to datatable:

Dim query = From c in db.Customers _
            Where c.Status = "Active" _
            Select c.CId, c.FirstName, c.LastName, c.Email

Thanks.

+1  A: 

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

Angkor Wat