开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜