欢迎使用C#或VB.NET中的示例。
我想将以下查询结果绑定到datatable:
Dim query = From c in db.Customers _
Where c.Status = "Active" _
Select c.CId, c.FirstName, c.LastName, c.Email
感谢。
答案 0 :(得分:1)
试试这个:
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