我现在一直在寻找如何做一个小时,但我看到的只是C#中的答案..我想按照以下顺序在Datagridview1
tbl_scancheck
显示数据(这些是列标题): Emp_No, DN_PickList, PickList_DT, DN_Thermal,Thermal_DT, TALLY
但是,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
答案 0 :(得分:3)
在您分配OleDbDataAdapter
的行中,您传递SELECT * FROM
SQL命令 -
da = New OleDbDataAdapter("Select * from [tbl_scancheck]", myConnection)
既然你知道了你想要的列的名称以及你想要它们的顺序,那么如果修改SQL以明确命名列,它可能会起作用吗?示例 -
da = New OleDbDataAdapter("SELECT Emp_No, DN_PickList, PickList_DT, DN_Thermal,Thermal_DT, [TALLY] FROM [tbl_scancheck]", myConnection)