查询Datagridview并输出到Datagridview vb.net

时间:2016-08-15 14:14:02

标签: sql vb.net datagridview

我只是想确保正确阅读microsoft的文档,并且我理解了结构。

首先是我正在阅读的链接:

https://msdn.microsoft.com/en-us/library/bb669099(v=vs.110).aspx

其次是他们建议的代码:

' Create a table from the bound view representing a query of 
' available products.
Dim view As DataView = CType(bindingSource1.DataSource, DataView)
Dim productsTable As DataTable = CType(view.Table, DataTable)

' Set RowStateFilter to display the current rows.
view.RowStateFilter = DataViewRowState.CurrentRows

' Query the DataView for red colored products ordered by list price.
Dim productQuery = From rowView As DataRowView In view _
                   Where rowView.Row.Field(Of String)("Color") = "Red" _
                   Order By rowView.Row.Field(Of Decimal)("ListPrice") _
                   Select New With {.Name = rowView.Row.Field(Of String)("Name"), _
                                .Color = rowView.Row.Field(Of String)("Color"), _
                                .Price = rowView.Row.Field(Of Decimal)("ListPrice")}

' Bind the query results to another DataGridView.
dataGridView2.DataSource = productQuery.ToList()

很抱歉,如果这看起来像一个愚蠢的问题,但我的询问主要与理解如何正确查询它有关。这段代码的“SELECT”部分是最后的,对吗? (即选择New With,column_name,column_name等)。很抱歉把它放在SQL术语中,但我想知道查询datagridview(使用它就像查询的临时表一样)是否更有效,而不是要回到DB或循环检查内容如此变数。

并且“bindingSource1”是第一个datagridview,还是源数据(db中的表)?

0 个答案:

没有答案