您好我正在尝试使用数据文件中的项填充datagridview。代码在.fill上停止。我在excel(Microsoft查询)中测试了查询,它在那里工作得很好。我也测试了它(在我的vb代码中)通过添加一个WHERE只接收特定条目,这工作正常。任何想法如何让我的应用程序工作?代码如下,感谢您的帮助!
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
答案 0 :(得分:0)
这篇文章帮了很多忙。 What's better: DataSet or DataReader? 所以我最终改变了我的代码以使用数据阅读器,到目前为止一直很好。