0

我可以在 OleDbCommand 的一个查询中在不同的表中执行两个 select 语句吗?我正在阅读一个 .dbf 文件,我想在上面填充我的数据集。

SELECT * FROM BILLHEAD SELECT * FROM BILLDETA

我收到一个错误

Syntax error in FROM clause.

这是我的代码:

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    oLoadDb("SELECT * FROM BILLHEAD " & vbCrLf & " SELECT * FROM BILLDETA")
    DataGridView1.DataSource = oDs.Tables(0).DefaultView 
    DataGridView2.DataSource = oDs.Tables(1).DefaultView

End Sub

Dim oDs As DataSet
Private Function oLoadDb(ByRef dbf_file As String)
    Try
        Dim FilePath As String = "D:\DBF"
        Dim SQLstr As String = dbf_file
        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath & _
        " ;Extended Properties=dBASE IV;User ID=Admin;Password="

        Try

            Dim DBFConn As New OleDbConnection(ConnString)
            DBFConn.Open()

            Dim DBFCommand As OleDbCommand = New OleDbCommand(SQLstr, DBFConn)
            Dim DBFDataReader As OleDbDataReader = DBFCommand.ExecuteReader(CommandBehavior.SequentialAccess)

            Dim daData As OleDbDataAdapter
            daData = New OleDbDataAdapter(SQLstr, DBFConn)
            oDs = New DataSet

            daData.Fill(oDs)
            DBFConn.Close()

        Catch ex As Exception
            Debug.WriteLine(ex.Message.ToString)
        End Try
    Catch ex As Exception

    End Try
End Function
4

2 回答 2

0

如果两个表具有相同的数据结构,你可以这样做

SELECT * FROM BILLHEAD 
UNION
SELECT * FROM BILLDETA

从表中获取所有数据

于 2013-12-04T07:50:48.607 回答
0

试试下面,批量执行

oLoadDb("SELECT * FROM BILLHEAD SELECT * FROM BILLDETA")

于 2013-12-04T07:54:11.637 回答