0

您好我正在尝试用数据文件中的项目填充数据网格视图。代码停在 .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
4

1 回答 1

0

这篇文章帮助很大。哪个更好:DataSet 还是 DataReader? 所以我最终改变了我的代码以使用数据阅读器,到目前为止一切都很好。

于 2013-04-01T17:01:12.350 回答