Datatable.Select() 方法是选择行,以填充您需要填充的每个 Datatable,如下所示:
Dim dt as DataTable
dt.Columns.Add("sID")
dt.Columns.Add("Column2")
Dim dr as Datarow
Dim i as integer
for i = 0 to 3
dr = dt.NewRow()
dr(0) = sID
dr(1) = "Column2Value"
dt.Rows.Add(dr)
next i
或者来自这样的数据库:
Sub FillData()
' 1
' Open connection
Using c As New SqlConnection(Properties.Settings.[Default].DataConnectionString)
c.Open()
' 2
' Create new DataAdapter
Using a As New SqlDataAdapter("SELECT * FROM EmployeeIDs", c)
' 3
' Use DataAdapter to fill DataTable
Dim t As New DataTable()
' 4
' Render data onto the screen
' dataGridView1.DataSource = t; // <-- From your designer
a.Fill(t)
End Using
End Using
End Sub