我一直在尋找如何做到這一個小時,但所有我看到的都是C#中的答案..我想在Datagridview1
中顯示tbl_scancheck
以下的數據爲了(這些是列標題):Emp_No, DN_PickList, PickList_DT, DN_Thermal,Thermal_DT, TALLY
如何將數據表的選定列綁定到datagridview
然而,tbl_scancheck
是按此順序:DN_PickList, PickList_DT, DN_Thermal,Thermal_DT, TALLY, Emp_No
當前tbl_scancheck順序目前正在另一個datagridview的使用,因此我不能手動編輯MS Access。
這裏是我當前的代碼:
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\austin\Documents\Visual Studio 2015\Projects\ScanCheckSystem\ScanCheckSystem\bin\Debug\packerdb.accdb"
Dim myConnection As OleDbConnection = New OleDbConnection(dbprovider)
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Private Sub Packer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [tbl_scancheck]", myConnection)
da.Fill(ds, "tbl_scancheck")
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub
在設計器中,按照您需要的順序在「DataGridView」中創建列。將'DataGridViewColumn'的'DataProperty'設置爲'DataTable'中列的相應名稱。並在設置'.DataSource'設置'DataGridView.AutoColumnGeneration = false'之前'Load'事件處理程序。 – Fabio