我可以在 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