您好我正在尝试用数据文件中的项目填充数据网格视图。代码停在 .fill 上。我在 excel(Microsoft 查询)中测试了查询,它在那里工作正常。我还通过添加一个仅在特定条目上接收的 WHERE 对其进行了测试(在我的 vb 代码中),这很好用。任何想法如何让它在我的应用程序中工作?代码如下,感谢您的帮助!
Dim dataAdapter As New Odbc.OdbcDataAdapter()
Private Sub ChangeSelect()
Dim selectCommand As String = "SELECT CWIPH.CUST_NO, CWIPH.JOB_NO, CWIPH.JOB_NAME, CJCMS.JOB_DESC FROM { OJ CWIPH CWIPH INNER JOIN CJCMS CJCMS ON CWIPH.JOB_NO = CJCMS.JOB_NO }"
accessDB(selectCommand)
End Sub
Private Sub accessDB(ByVal selectCommand As String)
Dim JobConnectionString As String = "Dsn=Jake; provider=System.Data.Odbc"
Dim cn As OdbcConnection = New OdbcConnection(JobConnectionString)
Dim table As New DataTable()
cn.Open()
Dim cmd As New Odbc.OdbcCommand(selectCommand, cn)
Me.dataAdapter = New Odbc.OdbcDataAdapter(cmd)
With dgvWorkOrder
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
End With
Dim commandBuilder As New Odbc.OdbcCommandBuilder(Me.dataAdapter)
Me.dataAdapter.Fill(table)
Me.dgvWorkOrder.DataSource = table
cn.Close()
End Sub