【问题标题】:Import specific columns of a DataTable in Visual Basic在 Visual Basic 中导入 DataTable 的特定列
【发布时间】:2016-12-06 12:17:51
【问题描述】:

我有一个包含多个列的 DataTable,我想将其中的一些列及其每一行的数据导入 VisualBasic 中的 DataGridView。 你能帮帮我吗?

【问题讨论】:

    标签: data-binding datagridview import


    【解决方案1】:

    您的问题非常笼统。无论哪种情况,这里都有一个示例。

    'Create a new datatable
          Dim table2 As New DataTable
          table2.Columns.Add("Name")
    
     'loop through your existing datatable - add the records to the columns you want
      For Each dr As DataRow In Table1.Rows
                 Dim R As DataRow = dt.NewRow
                 R("Name") = dr("TABLE1_COLUMNNAME")
                 dt.Rows.Add(R)
      Next
     'turn the new datatable into the datagridview. 
     DataGridView1.DataSource = table2 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多